Skip to content
This repository has been archived by the owner on Mar 30, 2022. It is now read-only.

Commit

Permalink
feat: Thin wrapper over node-fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
andreidmt committed May 20, 2020
1 parent 44a3eb2 commit 7c0a40d
Show file tree
Hide file tree
Showing 14 changed files with 331 additions and 370 deletions.
19 changes: 0 additions & 19 deletions .babelrc

This file was deleted.

8 changes: 0 additions & 8 deletions .browserslistrc

This file was deleted.

5 changes: 1 addition & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
"root": true,

"extends": [
"@mutant-ws/eslint-config/targets/html",
"@mutant-ws/eslint-config/targets/node",
],

"globals": {
require: true,
fixture: true,
test: true
},
Expand All @@ -23,8 +22,6 @@
"lifetime": 5,
},

// Can add a path segment here that will act like a source root, for
// in-project aliasing (i.e. `import MyStore from 'stores/my-store'`)
"import/resolver": {
"node": {
"extensions": [".js"],
Expand Down
51 changes: 8 additions & 43 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
Expand All @@ -20,12 +16,12 @@ lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output
.coveralls.yml

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
Expand All @@ -44,21 +40,12 @@ jspm_packages/
# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

Expand All @@ -70,36 +57,14 @@ typings/

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
# next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/
# Babel compile
dist/

# TernJS port file
# Sublime text
*.sublime-project
*.sublime-workspace
.tern-port
19 changes: 19 additions & 0 deletions .nycrc
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"
}
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ Releases and changelog are automaticly handled by [semantic-release](https://git

All releases are based on Angular's [Git commit message](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines) patterns.

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.
93 changes: 89 additions & 4 deletions README.md
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.
Loading

0 comments on commit 7c0a40d

Please sign in to comment.