3.0.0 • Published 10 months ago
eproxe-axios-extension v3.0.0
eproxe-axios-extension
Install
npm i eproxe-axios-extension
pnpm add eproxe-axios-extension
Usage
Convetions
This exntesion relies method naming conventions to keep the syntax to a minimum
- methods starting with
get
will result inGET
requests, 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
delete
will result inDELETE
requests, 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
post
will result inPOST
requests, the parameters passed to the method call will be passed as the request's body - methods starting with
put
will result inPUT
requests, the parameters passed to the method call will be passed as the request's body - defaults to
post
if 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 http
see a full example here