@lindorm-io/axios
TypeScript icon, indicating that this package has built-in type declarations

0.6.18 • Public • Published

@lindorm-io/axios

Axios Request Handler for lindorm.io packages.

Installation

npm install --save @lindorm-io/axios

Usage

Axios

Creates a wrapper around the axios package that makes it much easier to perform standard requests. Improves the request with new middleware configuration.

const axios = new Axios({
  alias: "ClientAlias",
  auth: {
    username: "basic-username",
    password: "basic-password",
  },
  baseUrl: "https://lindorm.io",
  middleware: [
    axiosTransformResponseDataMiddleware(TransformMode.CAMEL)
  ],
  headers: {
    "x-request-header": "string-value"
  },
}, logger);

const res = await axios.get("/path/:param_1", {
  params: { param_1: "value" },
});

const res = await axios.post("/path", {
  body: { key: "value" },
});

const res = await axios.put("/path", {
  body: { key: "value" },
});

const res = await axios.patch("/path", {
  body: { key: "value" },
});

const res = await axios.delete("/path", {
  headers: { "x-extra-header": "value" },
  query: { someThing: "hello" },
});

Middleware

With middleware you are able to add handlers that enhance or validate your request context before the Promise is resolved.

Middleware can be added to the constructor config, and it can be added as part of any request options.

const yourMiddleware: Middleware = async (context, next): Promise<void> => {
  console.log("before", context.req)

  await next()

  console.log("after", context.res)
};

const axios = new Axios({ middleware: [yourMiddleware] });

const response = await axios.put("/path", {
  middleware: [yourMiddleware],
});

Readme

Keywords

none

Package Sidebar

Install

npm i @lindorm-io/axios

Weekly Downloads

0

Version

0.6.18

License

AGPL-3.0-or-later

Unpacked Size

101 kB

Total Files

156

Last publish

Collaborators

  • princejonn