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

@biko/http-client

v0.1.3

Published

Wrapper for common http methods using different connectors (fetch, axios)

Downloads

4

Readme

Biko httpClient

Defines a wrapper on top of fetch or any HTTP library like Axios.

That wrapper is in fact a TypeScript interface, which any underlying connector must meet. Currently, two connectors are provided:

  • axios (completely functional)
  • fetch (at this moment, not functional and only present as a proof-of-concept)

Installation

npm install --save @biko/http-client

API

setConnector(connector: HttpClientConnector)

Sets httpClient connector. It must be of type HttpClientConnector and own the following members:

  • defaultConfig: { baseURL: Config; }
  • sendGet: (path: string, config?: Config)=> Promise<{ status: number; data: {} }>;
  • sendPost: (path: string, payload: {}, config?: Config)=> Promise<{ status: number; data: {} }>;
  • sendPut: (path: string, payload: {}, config?: Config)=> Promise<{ status: number; data: {} }>;
  • sendPatch: (path: string, payload: {}, config?: Config)=> Promise<{ status: number; data: {} }>;
  • sendDelete: (path: string, config?: Config)=> Promise<{ status: number; data: {} }>;
  • addRequestInterceptor: ( onFulfilled?: (config: Config) => Config | Promise<Config>, onRejected?: (error: any) => any, ): number;
  • addResponseInterceptor: ( onFulfilled?: (response: any) => any | Promise<any>, onRejected?: (error: any) => any, ): number;
  • removeRequestInterceptor: (id: number): void;
  • removeResponseInterceptor: (id: number): void;

Request and response interceptors are mainly based on Axios' interceptors, but they can be implemented using fetch or any other HTTP library. Please refer to them for further information.

Config type is: { baseURL: string; [index: string]: any; }

setDefaultConfig(config: Config)

Sets HttpClientConnector's default config. This is useful when connections are always done to the same API, using the same tokens/auth data, etc.

Example:

// myHttpClient.ts
import * as httpClient from 'biko-http-client';
import * as httpClientConnector from 'biko-http-client/lib/connectors/axios';

httpClient.setConnector(httpClientConnector);

httpClient.setDefaultConfig({
  baseURL: 'http://example.com/api',
  headers: {
    'X-user': 'myUsername',
    'X-password': 'myPassword',
  },
});

// Reexport only the functions your app is going to use
export const sendGet = httpClient.sendGet;
export const sendPost = httpClient.sendPost;
...

// ...or export the whole httpClient if your app uses all functions
export { httpClient };
// myComponent.ts
import { sendGet } from './myHttpClient';
sendGet('/my-path').then(response => {
  console.log(response.status);
  console.log(response.data);
});