This repository has been archived by the owner on Mar 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
331 additions
and
370 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"lines": 100, | ||
"statements": 100, | ||
"functions": 100, | ||
"branches": 100, | ||
"include": [ | ||
"src/**/*.js" | ||
], | ||
"exclude": [ | ||
"src/**/*.test.js", | ||
"src/**/*.bench.js" | ||
], | ||
"reporter": [], | ||
"cache": true, | ||
"all": true, | ||
"sourceMap": true, | ||
"instrument": true, | ||
"report-dir": "./coverage" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,101 @@ | ||
<!-- markdownlint-disable line-length --> | ||
|
||
# fetch | ||
# fetch-node | ||
|
||
Thin wrapper over [`node-fetch`](https://github.com/node-fetch/node-fetch). Sister libray of [`@mutant-ws/fetch-browser`](https://github.com/mutant-ws/fetch-browser). | ||
|
||
<!-- vim-markdown-toc GFM --> | ||
|
||
* [About](#about) | ||
* [Install](#install) | ||
* [Initialize](#initialize) | ||
* [Default headers](#default-headers) | ||
* [Query string parameters](#query-string-parameters) | ||
* [`GET`](#get) | ||
* [`PATCH`](#patch) | ||
* [`POST`](#post) | ||
* [`DELETE`](#delete) | ||
* [`MULTIPART`](#multipart) | ||
* [Changelog](#changelog) | ||
|
||
<!-- vim-markdown-toc --> | ||
|
||
## About | ||
## Install | ||
|
||
```bash | ||
npm i @mutant-ws/fetch-node | ||
``` | ||
|
||
## Initialize | ||
|
||
```javascript | ||
import { set } from "@mutant-ws/fetch-node" | ||
|
||
set({ | ||
// Throws if not set and using relative paths | ||
baseURL: "http://localhost", | ||
}) | ||
``` | ||
|
||
### Default headers | ||
|
||
```javascript | ||
import { set } from "@mutant-ws/fetch-node" | ||
|
||
set({ | ||
// Persistent headers | ||
headers: { | ||
// Library defaults | ||
"accept": "application/json", | ||
"content-type": "application/json", | ||
|
||
// Set JWT for authorized requests | ||
authorization: "signed-payload-with-base64-over", | ||
}, | ||
}) | ||
``` | ||
|
||
### Query string parameters | ||
|
||
There is no built-in way to handle query params but you can set a custom | ||
transform function. | ||
|
||
```javascript | ||
import { set } from "@mutant-ws/fetch-node" | ||
import { stringify } from "qs" | ||
|
||
set({ | ||
// Throws if query params passed and no stringify function defined | ||
queryStringifyFn: source => | ||
stringify(source, { | ||
allowDots: true, | ||
encode: false, | ||
arrayFormat: "brackets", | ||
strictNullHandling: true, | ||
}) | ||
}) | ||
``` | ||
|
||
## `GET` | ||
|
||
```javascript | ||
import { GET } from "@mutant-ws/fetch-node" | ||
|
||
const myIP = await GET("https://api.ipify.org", { | ||
query: { | ||
format: "json" | ||
} | ||
}) | ||
// => {"ip":"213.127.80.141"} | ||
``` | ||
|
||
## `PATCH` | ||
|
||
## `POST` | ||
|
||
## `DELETE` | ||
|
||
## `MULTIPART` | ||
|
||
## Changelog | ||
|
||
See the [releases section](https://github.com/mutant-ws/fetch/releases) for details. | ||
See the [releases section](https://github.com/mutant-ws/fetch-node/releases) for details. |
Oops, something went wrong.