Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gawsoftpl/rest-client-framework
https://github.com/gawsoftpl/rest-client-framework
Last synced: 9 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/gawsoftpl/rest-client-framework
- Owner: gawsoftpl
- License: mit
- Created: 2022-02-06T04:09:46.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-02-20T03:00:18.000Z (11 months ago)
- Last Synced: 2024-11-07T08:37:22.838Z (about 2 months ago)
- Language: TypeScript
- Size: 234 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# About
Rest client framework for your api client. In below example how to use this simple scriptWrite quick your api client
# Example```js
// Client Stratgy
import { ClientInterface, Request, Response, ConfigType, ResponseInterface } from "@gawsoft/rest-api-client-framework";export class ClientTest implements ClientInterface {
private api_key: string;constructor(api_key: string) {
this.setApiKey(api_key);
}setApiKey(api_key: string) {
this.api_key = api_key;
}config(): ConfigType {
return {
endpoint: "https://httpbin.org",
timeout: 10000,
};
}globalHeaders(): Record {
return {};
}setAuthentication(request: Request): void {
request.addHeaders({ authorization: `Bearer ${this.api_key}` });
}
// Controllers
async extract(url: string): Promise {
const request = new Request(this);request.addHeaders({
"Accept-Encoding": "gzip",
"Content-Type": "application/json",
});const response = await request.post(`/person`, { name: "Johnny Kowalski" });
if (response.status !== 200)
throw new Error(
`Cant download json file from server status code: ${response.status}`
);return new Response(response);
}
}```