npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@revas-hq/kit-fetch

v0.0.3

Published

The `@revas-hq/kit-fetch` package provides a flexible way to enhance the `fetch` function with context-aware middleware. This package allows for injecting values like authorization headers and base URLs into fetch requests, making it easier to manage API

Downloads

19

Readme

Kit Fetch Library

The @revas-hq/kit-fetch package provides a flexible way to enhance the fetch function with context-aware middleware. This package allows for injecting values like authorization headers and base URLs into fetch requests, making it easier to manage API calls in your application.

Installation

Install the package using npm or yarn:

npm install @revas-hq/kit-fetch
# or
yarn add @revas-hq/kit-fetch

Usage

Creating a Context-Aware Fetch Function

import { createBaseUrlFetch, createContextFetch } from "@revas-hq/kit-fetch";
import type { Context } from "@revas-hq/kit-context";

const context: Context = {}; // Mock or create a context if needed
const baseApiUrl = "https://api.example.com/";

const fetchWithMiddlewares = createContextFetch(createBaseUrlFetch(baseApiUrl))(
  context,
);

fetchWithMiddlewares("endpoint")
  .then((response) => console.log(response))
  .catch((error) => console.error(error));

Types and Interfaces

FetchMiddleware

A type for middleware that wraps the fetch function.

export type FetchMiddleware = (next: typeof fetch) => typeof fetch;
ContextFetchMiddleware;

A type for context-aware fetch middleware.

export type ContextFetchMiddleware = (context: Context) => FetchMiddleware;
ContextFetchFunction;

A type for creating a fetch function based on context.

export type ContextFetchFunction = (context: Context) => typeof fetch;

Functions

createBaseUrlFetch

Creates a middleware that adds a base URL to the request. Ensures the base URL ends with a slash.

export const createBaseUrlFetch: (baseUrl: string) => ContextFetchMiddleware;

createContextFetch

Creates a context-aware fetch function from a list of middleware factories.

export const createContextFetch: (
  ...factories: ContextFetchMiddleware[]
) => ContextFetchFunction;

License

This project is licensed under the MIT License. See the LICENSE file for details.