mirror of
https://codeberg.org/reflect/reflect-client-js.git
synced 2025-11-05 01:02:40 +01:00
PHP module for communicating with an API built with Reflect over HTTP
| src | ||
| .gitignore | ||
| .npmignore | ||
| package-lock.json | ||
| package.json | ||
| README.md | ||
| tsconfig.json | ||
Reflect API client for JavaScript
Make requests to an API built using the Reflect API framework over HTTP with JavaScript.
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:
![]() Chrome |
![]() Firefox |
![]() Safari |
NodeJS |
Deno |
|---|---|---|---|---|
| ✅ 80+ | ✅ 75+ | ✅ 14.1+ | ✅ 20.7.0+ | ✅ 1.37.0+ |
How to use
-
Install with npm
npm i reflect-client -
Initialize the class
import { Client, Method } from "./reflect-client/Reflect.js const api = new Client("<api_url>", "<optional_api_key"); -
Make API request
Use the
call()method to perform a requestapi.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 (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/jsonThe
call()function will return a Response object
Development
NodeJS required version: 20.7.0+
TypeScript required version: 5.2.2+


