3.0.0 • Published 2 years ago
eproxe-axios-extension v3.0.0
eproxe-axios-extension
Install
npm i eproxe-axios-extensionpnpm add eproxe-axios-extensionUsage
Convetions
This exntesion relies method naming conventions to keep the syntax to a minimum
- methods starting with
getwill result inGETrequests, the parameters passed to the method call will be passed as query parameters on the request, the parameters will be human readable using JSON->URL - methods starting with
deletewill result inDELETErequests, the parameters passed to the method call will be passed as query parameters on the request, the parameters will be human readable using JSON->URL - methods starting with
postwill result inPOSTrequests, the parameters passed to the method call will be passed as the request's body - methods starting with
putwill result inPUTrequests, the parameters passed to the method call will be passed as the request's body - defaults to
postif none of these convetions are met
Example
client/api.ts
import axios from 'axios';
import eproxe from 'eproxe';
import AxiosProxyExtension from 'eproxe-axios-extension';
import type ServerAPI from '../../server/api';
const axiosInstance = axios.create({ baseURL: 'http://localhost:3000' });
const AxiosExtension = new AxiosProxyExtension(axiosInstance);
const api = AxiosExtension.extend(eproxe<ServerAPI>());
api.users.getUserById(1).then(console.log);
// ^ AxiosResponse
// GET request is sent over httpsee a full example here