https://github.com/sapfir0/axioswrapper
https://github.com/sapfir0/axioswrapper
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/sapfir0/axioswrapper
- Owner: Sapfir0
- Created: 2021-07-24T18:42:01.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-11-13T08:30:09.000Z (over 2 years ago)
- Last Synced: 2025-01-26T11:24:05.394Z (3 months ago)
- Language: TypeScript
- Size: 45.9 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Api interaction services
224kb
All services use `fp-ts` library, http methods wrapper return `fp-ts` either.
## Simple api interaction class```ts
import { ApiInteractionService } from 'api_interaction_services';
```So you can use it like this:
0.2x:
```ts
const fetcher = new ApiInteractionService("http://localhost:3300");
fetcher.get('/');
```0.3x:
```ts
const fetcher = new ApiInteractionService("http://localhost:3300");
fetcher.get('/')();
```## Indendity interaction service
A more powerful tool that allows you to communicate with a closed API that requires access and refresh tokens.
```ts
import { BearerApiInteractionService } from 'api_interaction_services';
```## Inversify
Or you can use this classes with inverisify in a few steps:
1. Declare SERVICE_IDENTIFIER name for service
```ts
export const SERVICE_IDENTIFIER = {
ApiInteractionService: Symbol.for("ApiInteractionService"),
};
```2. Bind this name to class with url to your API
```ts
container.bind(SERVICE_IDENTIFIER.ApiInteractionService).toConstantValue(new ApiInteractionService(API_URL));
```3. And now you can inject this service to your class
```ts
constructor(@inject(SERVICE_IDENTIFIER.ApiInteractionService) protected _apiService: ApiInteractionService) {}
```