mirror of
https://codeberg.org/reflect/reflect-client-js.git
synced 2025-09-13 20:23:41 +02:00
feat(doc): add README
This commit is contained in:
parent
fbea20b268
commit
e7810249aa
1 changed files with 56 additions and 0 deletions
56
README.md
Normal file
56
README.md
Normal file
|
@ -0,0 +1,56 @@
|
|||
# Reflect API client for JavaScript
|
||||
|
||||
Make requests to an API built using the [Reflect API](https://github.com/VictorWesterlund/reflect) framework over HTTP with JavaScript.
|
||||
|
||||
---
|
||||
|
||||
```js
|
||||
import { Client, Method } from "./reflect-client/Reflect.js
|
||||
|
||||
const api = new Client("<api_url>", "<optional_api_key");
|
||||
// Make an API request with Client.call() which returns a normal JavaScript Response object
|
||||
api.call("my/endpoint", Method.GET); // obj<Respone>
|
||||
```
|
||||
|
||||
## Supported browsers/environments:
|
||||
<br>Chrome|<br>Firefox|<br>Safari|<br>NodeJS|<br>Deno
|
||||
--|--|--|--|--
|
||||
✅ 80+|✅ 75+|✅ 14.1+|✅ 20.7.0+|✅ 1.37.0+
|
||||
|
||||
## How to use
|
||||
|
||||
1. **Install with npm**
|
||||
|
||||
```
|
||||
npm i reflect-client
|
||||
```
|
||||
|
||||
2. **Initialize the class**
|
||||
|
||||
```js
|
||||
import { Client, Method } from "./reflect-client/Reflect.js
|
||||
|
||||
const api = new Client("<api_url>", "<optional_api_key");
|
||||
```
|
||||
|
||||
3. **Make API request**
|
||||
|
||||
Use the `call()` method to perform a request
|
||||
|
||||
```js
|
||||
api.call("my/endpoint", Method.GET);
|
||||
```
|
||||
|
||||
Argument index|Type|Required|Description
|
||||
--|--|--|--
|
||||
0|string|Yes|Fully qualified pathname and query params of the endpoint to call
|
||||
1|Method\|string|Yes|A supported [Reflect HTTP method](https://github.com/VictorWesterlund/reflect/wiki/Supported-technologies#http-request-methods) (eg. `Method.GET`) or a string represnetation of a supported method (eg. "GET")
|
||||
2|array|No|An optional indexed, associative, or multidimensional array that will be sent as the request body as `Content-Type: application/json`
|
||||
|
||||
The `call()` function will return a [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) object
|
||||
|
||||
# Development
|
||||
|
||||
NodeJS required version: 20.7.0+
|
||||
|
||||
TypeScript required version: 5.2.2+
|
Loading…
Add table
Reference in a new issue