UNPKG

857 BMarkdownView Raw
1# proto-fetch
2
3[![build status](https://img.shields.io/github/actions/workflow/status/bergos/proto-fetch/test.yaml?branch=master)](https://github.com/bergos/proto-fetch/actions/workflows/test.yaml)
4[![npm version](https://img.shields.io/npm/v/proto-fetch.svg)](https://www.npmjs.com/package/proto-fetch)
5
6A protocol handler wrapper for fetch.
7
8## Usage
9
10`proto-fetch` doesn't contain any fetch implementations.
11A map of protocol to implementation must be given to the constructor.
12This example shows how to create a fetch for file, http and https URLs:
13
14```javascript
15import fileFetch from 'file-fetch'
16import httpFetch from 'nodeify-fetch'
17import protoFetch from 'proto-fetch'
18
19const fetch = protoFetch({
20 [null]: fileFetch,
21 file: fileFetch,
22 http: httpFetch,
23 https: httpFetch
24})
25
26const res = await fetch(`file://${process.cwd()}/package.json`)
27```
28
\No newline at end of file