Skip to content

Commit

Permalink
Update project documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
alexghr committed Sep 17, 2019
1 parent ab787f4 commit 0bec792
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 2 deletions.
69 changes: 67 additions & 2 deletions README.md
@@ -1,10 +1,75 @@
# got-fetch

A `fetch`-compatible wrapper around [got].
A `fetch`-compatible wrapper around [got] for those times when you need to
fetch stuff over HTTP 😉

## Install

`got` is a peer dependency so you will need to install it alongside `got-fetch`:

```sh
$ npm install --save got got-fetch
```

If you use Typescript then you will also need `@types/got` if you want your
project to build:

```sh
$ npm install --save-dev @types/got
```

## Usage

The module exports a global instance ready to fetch resources:

```js
const { fetch } = require('got-fetch');

fetch('https://example.com').then(resp => {
console.log(resp.status); // should be 200
resp.text().then(body => console.log(body)); // should be some HTML code
});
```

The module also exports a function which allows you to use your own custom
`got` instance:

```js
const got = require('got');
const { createFetch } = require('got-fetch');

const myGot = got.extend({
headers: {
'x-api-key': 'foo bar'
}
});

const fetch = createFetch(myGot);

// this request will send the header `x-api-key: foo bar`
fetch('https://example.com');
```

## Limitations

`fetch` is designed for browser environments and this package is just a wrapper
around a Node-based HTTP client. Not all `fetch` features are supported:
-[RequestMode] `no-cors`, `same-origin`, `navigate`
-[RequestCache] `only-if-cached`
-[RequestRedirect] `error`, `manual`
-[RequestHeaders] must be a plain object
-[RequestCache] if unset (or `default`) will use got's [caching algorithm]
(any other value will disable caching)

## License

See [LICENSE] for information.

[got]: https://github.com/sindresorhus/got
[LICENSE]: ./LICENSE
[LICENSE]: ./LICENSE

[RequestMode]: https://fetch.spec.whatwg.org/#concept-request-mode
[RequestCache]: https://fetch.spec.whatwg.org/#concept-request-cache-mode
[RequestRedirect]: https://fetch.spec.whatwg.org/#concept-request-redirect-mode
[RequestHeaders]: https://fetch.spec.whatwg.org/#ref-for-concept-request-header-list
[caching algorithm]: https://github.com/sindresorhus/got/tree/f59a5638b93c450dc722848b58b09a44f730a66f#cache-adapters
10 changes: 10 additions & 0 deletions package.json
Expand Up @@ -2,6 +2,16 @@
"name": "got-fetch",
"version": "1.0.0-rc.1",
"license": "MIT",
"description": "A fetch-compatible interface to the got HTTP client",
"homepage": "https://github.com/alexghr/got-fetch#readme",
"repository": {
"type": "git",
"url": "https://github.com/alexghr/got-fetch.git"
},
"bugs": {
"url": "https://github.com/alexghr/got-fetch/issues"
},
"author": "Alex Gherghisan <alexghr@users.noreply.github.com> (https://alexghr.me)",
"main": "./out/lib",
"types": "./out/lib",
"scripts": {
Expand Down

0 comments on commit 0bec792

Please sign in to comment.