2.1.1 • Published 1 year ago

base-fetch v2.1.1

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Fetch-based wrapper!

Requires NodeJS v17.5.0 or newer.

Github repository

Installation

npm install base-fetch

Documentation

If you are using typescript, the following libraries should be provided in your tsconfig file: "DOM", "DOM.Iterable", "ES2015"

Core

Addon

Utilities

You can use dev tools to test following example. Do not forget to include request function into you environment (browser, node...) and then the rest of the items if needed, such as unwrap for example

Example requests can be done at https://jsonplaceholder.typicode.com

Use this helper:

const base = new URL('https://jsonplaceholder.typicode.com')

Basic usage example in browser or node runtimes

import { request, unwrap } from 'base-fetch'

const url = new URL('todos', base)

request(url)
  .then(unwrap)
  .then(console.log)
  .catch(reason => console.error(reason))

Providing type information

interface Shape {
  id: number
}

request<Shape>(url)
  .then(unwrap)
  .then(value => value.id)

Core

request

Request from from the given resource.

Learn:

  • Request (RequestInfo and RequestInit are typescript definitions)

example

const url = new URL('todos', base)

request('https://jsonplaceholder.typicode.com/todos')

request(url, { method: 'GET' })

request(url, { method: 'POST', body: JSON.stringify({}) })

request(url, { method: 'PUT', body: new FormData() })

request(url, { method: 'DELETE', signal: new AbortController().signal })

request(url, { method: 'PATCH', credentials: 'include' })

Addon

pipe

Will be written...

Utilities

unwrap

Simple functions taht provides a little bit more cleaner syntax when working with request's return value

example

request(url)
  .then(unwrap)
  .then(value => value)
2.0.3

1 year ago

2.1.1

1 year ago

2.0.2

1 year ago

2.0.4

1 year ago

2.1.0

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.5.7

1 year ago

1.5.69

1 year ago

1.5.68

1 year ago

1.5.67

1 year ago

1.5.66

1 year ago

1.5.65

1 year ago

1.5.64

1 year ago

1.5.63

1 year ago

1.5.62

1 year ago

1.5.61

1 year ago

1.5.6

1 year ago

1.5.5

1 year ago

1.5.4

1 year ago

1.5.3

1 year ago

1.5.2

1 year ago

1.5.1

1 year ago

1.5.0

1 year ago

1.4.6

1 year ago

1.3.6

1 year ago

1.3.5

1 year ago

1.3.4

1 year ago

1.3.3

1 year ago

1.3.2

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago