Skip to content

Commit

Permalink
review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Yves Darmaillac committed Jun 13, 2022
1 parent 791e1e4 commit 7536551
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
19 changes: 12 additions & 7 deletions documentation/quickstart.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Quick start guide

This quick start uses ES2017 syntax.

## Getting and posting data with promises

The simplest `GET` request :
Expand Down Expand Up @@ -30,8 +28,11 @@ const options = {
headers: {
"Custom-Header": "Quick start",
},
timeout: { send: 3500 },
timeout: {
send: 3500
},
};

const data = await got(url, options).json();
```

Expand Down Expand Up @@ -65,7 +66,7 @@ got.stream.post(url, options).pipe(outStream);

## Options

Options can be set at client level and reused in subsequent queries :
Options can be set at client level and reused in subsequent queries:

```js
import got from "got";
Expand Down Expand Up @@ -100,15 +101,19 @@ import got from "got";

const data = await got
.get("https://httpbin.org/status/404")
.catch((e) => console.error(e.code, e.message));
.catch(error => {
console.error(error.code, error.message)
});
```

```js
import got from "got";

got.stream
.get("https://httpbin.org/status/404")
.once("error", (e) => console.error(e.code, e.message))
.once("error", error => {
console.error(error.code, error.message)
})
.pipe(fs.createWriteStream("anything.json"));
```

Expand Down Expand Up @@ -172,7 +177,7 @@ import got from "got";

const logRetry = (error, retryCount) => {
console.error(`Retrying after error ${error.code}, retry #: ${retryCount}`);
}
};

const options = {
hooks: {
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ npm install got
**Warning:** This package is native [ESM](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) and no longer provides a CommonJS export. If your project uses CommonJS, you'll have to [convert to ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) or use the [dynamic `import()`](https://v8.dev/features/dynamic-import) function. Please don't open issues for questions regarding CommonJS / ESM. You can also use [Got v11](https://github.com/sindresorhus/got/tree/v11.8.3) instead which is pretty stable.

## Take a peek

**A [quick start](documentation/quickstart.md) guide is available.**

### JSON mode
Expand Down

0 comments on commit 7536551

Please sign in to comment.