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 |
|
6 | A protocol handler wrapper for fetch.
|
7 |
|
8 | ## Usage
|
9 |
|
10 | `proto-fetch` doesn't contain any fetch implementations.
|
11 | A map of protocol to implementation must be given to the constructor.
|
12 | This example shows how to create a fetch for file, http and https URLs:
|
13 |
|
14 | ```javascript
|
15 | import fileFetch from 'file-fetch'
|
16 | import httpFetch from 'nodeify-fetch'
|
17 | import protoFetch from 'proto-fetch'
|
18 |
|
19 | const fetch = protoFetch({
|
20 | [null]: fileFetch,
|
21 | file: fileFetch,
|
22 | http: httpFetch,
|
23 | https: httpFetch
|
24 | })
|
25 |
|
26 | const res = await fetch(`file://${process.cwd()}/package.json`)
|
27 | ```
|
28 |
|
\ | No newline at end of file |