Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@uxland/fetch-client

Package Overview
Dependencies
Maintainers
2
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@uxland/fetch-client

Fetch Client

  • 1.0.1-alpha.17
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
22
increased by4.76%
Maintainers
2
Weekly downloads
 
Created
Source

UXL Fetch Client npm version

Build StatusStatementsBranchesFunctionsLines
BuildStatusStatementsBranchesFunctionsLines

Installation

npm i @uxland/fetch-client

Usage

Configuration

Set Base URL

All relative fetch will use provided url as its own base URL. If using absolute uri when fetching, this will not be taken into account.

import { setBaseUrl } from "@uxland/fetch-client";
setBaseUrl("http://localhost");

Register response handlers

Register a response handler to manipulate result.

import { registerResponseHandler } from "@uxland/fetch-client";
registerResponseHandler((response) => JSON.stringify(response));

Change fetch client configuration

Change configuration globally. All fetch requests will use this configuration.

import { configure } from '@uxland/fetch-client';
configure({mode: 'no-cors',{ headers: {authorization: 'Bearer <token>' }}});

Change fetch client headers

Change headers globally. All fetch requests will use specified headers.

import { setHeaders } from "@uxland/fetch-client";
setHeaders({ authorization: "Bearer <token>" });

Delete specific header

Remove a header from global headers using provided id.

import { removeHeader } from "@uxland/fetch-client";
removeHeader("authorization");

Reset fetch client headers

Reset global headers to default.

import { resetHeaders } from "@uxland/fetch-client";
resetHeaders();

Fetch data

import { doFetch } from "@uxland/fetch-client";
const response = doFetch("/dummy", { mode: "no-cors" }, { foo: "bar" })
  .then((r) => r)
  .catch((e) => e);

In addition, fetchClient also publishes (via @uxland/event-aggregator) two events INVALID_CREDENTIALS_EVENT and INVALID_REQUEST_EVENT when credentials are invalid or request has failed.

FAQs

Package last updated on 03 Jun 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc