1.0.1 • Published 3 years ago

@uxland/fetch-client v1.0.1

Weekly downloads
2
License
BSD-4-Clause
Repository
github
Last release
3 years ago

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.

1.0.1

3 years ago

1.0.1-alpha.22

3 years ago

1.0.1-alpha.21

3 years ago

1.0.1-alpha.20

3 years ago

1.0.1-alpha.15

3 years ago

1.0.1-alpha.14

3 years ago

1.0.1-alpha.13

3 years ago

1.0.1-alpha.19

3 years ago

1.0.1-alpha.18

3 years ago

1.0.1-alpha.17

3 years ago

1.0.1-alpha.16

3 years ago

1.0.1-alpha.12

4 years ago

1.0.1-alpha.11

4 years ago

1.0.1-alpha.9

4 years ago

1.0.1-alpha.8

4 years ago

1.0.1-alpha.10

4 years ago

1.0.1-alpha.7

4 years ago

1.0.1-alpha.6

4 years ago

1.0.1-alpha.5

4 years ago

1.0.1-alpha.4

4 years ago

1.0.1-alpha.3

4 years ago

1.0.0

4 years ago

1.0.1-alpha.2

4 years ago

1.0.1-alpha.1

4 years ago

1.0.1-alpha.0

4 years ago

1.0.0-alpha.21

4 years ago

1.0.0-alpha.20

4 years ago

1.0.0-alpha.19

4 years ago

1.0.0-alpha.18

4 years ago

1.0.0-alpha.17

4 years ago

1.0.0-alpha.16

4 years ago

1.0.0-alpha.15

4 years ago

1.0.0-alpha.14

4 years ago

1.0.0-alpha.13

4 years ago

1.0.0-alpha.12

4 years ago

1.0.0-alpha.11

4 years ago

1.0.0-alpha.10

5 years ago

1.0.0-alpha.9

5 years ago

1.0.0-alpha.8

5 years ago

1.0.0-alpha.7

5 years ago

1.0.0-alpha.6

5 years ago

1.0.0-alpha.5

5 years ago

1.0.0-alpha.4

5 years ago

1.0.0-alpha.3

5 years ago

1.0.0-alpha.2

5 years ago

1.0.0-alpha.1

5 years ago

1.0.0-alpha.0

5 years ago