0.2.1 • Published 6 years ago

superagent-use-middleware v0.2.1

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

superagent-use-middleware

A superAgent plugin helps you to create a middleware.

Under the hood, this module will call .use function on all superAgent request objects you specified rather than traditionally you will need to call them every time. (please see examples below) This module is written in typescript, the superAgent type definition is a part of this project's dependency.

examples

import superAgent from 'superagent'
import makeMiddleware from 'superagent-use-middleware'
const request = makeMiddleware(
  superAgent, // the superAgent object
  ['get', 'post', 'put', 'delete', 'options'] // (optional) methods you want to insert this middleware to 
)

// example: you want to inject a custom header to all requests
export default request.use((req) => {
  req.header['api-version'] = 10
  return req
})

// then you can call e.g. request.get(url) from other files that have this imported

NOTE: This project is based on superagent-use, adding typescript support, removed node-methods and assign dependencies. Great shout out to authors of superagent-use.

0.2.1

6 years ago

0.2.0

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago