Package Exports
- @feedma/http-service
- @feedma/http-service/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@feedma/http-service) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
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();
};