@feedma/http-service
v1.0.2
Published
A class based HTTP client built on top of axios
Downloads
1
Maintainers
Readme
Quickstart
Installation
See the full documentation
NPM
npm i axios @feedma/http-service
YARN
yarn add axios @feedma/http-service
Create a service
Typescript
// JsonPlaceHolderService.ts
import { HttpService } from '@feedma/http-service';
import { AxiosRequestConfig } from 'axios';
export class JsonPlaceHolderService extends HttpService {
protected config: AxiosRequestConfig = {
baseURL: "https://jsonplaceholder.typicode.com" ,
};
async fetchUsers(): Promise<AxiosResponse> {
return this.client.get('/users');
}
// Yor request methods here ...
}
Javascript
// JsonPlaceHolderService.js
import { HttpService } from '@feedma/http-service';
export class JsonPlaceHolderService extends HttpService {
constructor(requestInterceptors = [], responseInterceptors = []) {
super(requestInterceptors, responseInterceptors);
this.config = {
baseURL: "https://jsonplaceholder.typicode.com",
};
}
async fetchUsers() {
return this.client.get('/users');
}
// Yor request methods here ...
}
Make request
Typescript
// app.ts
import { JsonPlaceHolderService } from './JsonPlaceHolderService';
const service: JsonPlaceHolderService = new JsonPlaceHolderService();
const app = async () => {
const { data } = await service.fetchUsers();
};
Javascript
// app.js
import { JsonPlaceHolderService } from './JsonPlaceHolderService';
const service = new JsonPlaceHolderService();
const app = async () => {
const { data } = await service.fetchUsers();
};