Skip to content

Commit

Permalink
doc: add example for follow redirects, remove outdated links
Browse files Browse the repository at this point in the history
  • Loading branch information
ethan7g committed Apr 10, 2024
1 parent bf9a480 commit b358267
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Then let's make a request in an async function!

```js
;(async () => {
const res = await c('https://ethanent.me').send()
const res = await c('https://example.com').send()

console.log(await res.text())
})()
Expand Down Expand Up @@ -78,7 +78,7 @@ c('https://example.com/user').query({
### Set a request timeout

```js
c('https://ethanent.me').timeout(2000).send().then((res) => {
c('https://example.com').timeout(2000).send().then((res) => {
// Success!
}).catch((err) => {
// Has the request timed out?
Expand All @@ -92,29 +92,29 @@ In this example, the [stream](https://nodejs.org/api/stream.html) is piped to a
```js
// require the fs module beforehand

c('https://ethanent.me/images/mainLogo.png').stream().send().then((stream) => stream.pipe(fs.createWriteStream(path.join(__dirname, 'logo.png'))))
c('https://example.com').stream().send().then((stream) => stream.pipe(fs.createWriteStream(path.join(__dirname, 'logo.png'))))
```

### Switch paths on the fly

```js
c('https://ethanent.me/test').path('/hello').send()
c('https://example.com/test').path('/hello').send()

// This will make a request to https://ethanent.me/test/hello
// This will make a request to https://example.com/test/hello
```

### Specify request headers

One at a time:

```js
c('https://ethanent.me').header('Content-Type', 'application/json').send()
c('https://example.com').header('Content-Type', 'application/json').send()
```

Many at a time:

```js
c('https://ethanent.me').header({
c('https://example.com').header({
'Content-Type': 'application/json',
'X-Connecting-With': 'centra'
}).send()
Expand All @@ -126,13 +126,13 @@ See [http.request](https://nodejs.org/dist/latest-v10.x/docs/api/http.html#http_
Let's change our localAddress as an example.

```js
c('https://ethanent.me').option('localAddress', '127.0.0.2').send()
c('https://example.com').option('localAddress', '127.0.0.2').send()
```

### Accept compressed responses

```js
c('https://ethanent.me').compress().send()
c('https://example.com').compress().send()

// This will cause centra to accept compressed content from the server. (gzip and deflate are currently supported)
```
```

0 comments on commit b358267

Please sign in to comment.