eproxe-axios-extension
v3.0.0
Published
<p align="center"> <img src="../../images/eproxe.svg"/> </p> <h2 align="center">+</h2> <p align="center"> <img width="400px" src="https://camo.githubusercontent.com/272811d860f3fab0dd8ff0690e2ca36afbf0c96ad44100b8d42dfdce8511679b/68747470733a2f2f617869
Downloads
4
Readme
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