3.0.0 • Published 10 months ago

eproxe-axios-extension v3.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
10 months ago

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 in GET 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 in DELETE 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 in POST requests, the parameters passed to the method call will be passed as the request's body
  • methods starting with put will result in PUT 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

3.0.0

10 months ago

2.0.0

11 months ago

1.0.0

11 months ago