Skip to content

Familiar Fetch API with support for custom middleware.

License

Notifications You must be signed in to change notification settings

ondrejsevcik/fetch-with-middleware

Repository files navigation

fetch-with-middleware

Familiar Fetch API with support for custom middleware.

Installation

Use npm to install the package.

npm install fetch-with-middleware

Usage

import { buildFetch, type MiddlewareFn } from 'fetch-with-middleware';

// Custom middleware function that will 
// log to console every request and response.
const logToConsole: MiddlewareFn = (next) => (request) => {
    console.log("Request", request);

    return next(request).then((response) => {
        console.log("Response", response);
        return response;
    });
};

const myFetch = buildFetch({ middleware: [logToConsole] });
const response = await myFetch("https://localhost:3000");

About

Familiar Fetch API with support for custom middleware.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published