1.0.6 • Published 4 years ago

fej v1.0.6

Weekly downloads
4
License
ISC
Repository
github
Last release
4 years ago

fej

Fetch API with middleware

fej exposes simple middleware API to manipulate request properties.

You can override middleware and initial data with each request: fej("/api/users", { headers: {"Accept": "application/xml"} })

Install

  npm install fej

Usage

See following usage examples

Fej.setInit

Set some static headers

  import Fej from "fej";

  Fej.setInit({
    headers: {
      "Accept": "application/json",
      "Content-Type": "application/json"
    }
  });

Fej.addAsyncMiddleware

Updating fetch properties asynchronously

  import Fej from "fej";

  Fej.addAsyncMiddleware(async init => {

    // get access token
    const token = await authService.acquireTokenSilent();

    // update Authorization header with new access token
    return Promise.resolve({
      headers: { Authorization: "Bearer " + token.accessToken }
    });
  });

Fej.addMiddleware

  import Fej from "fej";

  Fej.addMiddleware(init => {

    // Get current time
    const currentDateTime = new Date().toISOString()

    // update Authorization header with new access token
    return {
      headers: { "Z-CURRENTTIME": currentDateTime }
    };
  });
1.0.6

4 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago