Skip to content

Commit

Permalink
Provide an example
Browse files Browse the repository at this point in the history
  • Loading branch information
szmarczak committed Jun 21, 2019
1 parent 6c9aaa6 commit c82447c
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,37 @@ JSON body. If the `Content-Type` header is not set, it will be set to `applicati

Type: `unknown`

User data. In contrast to other options, `userData` is not enumerable.
User data. In contrast to other options, `userData` is not enumerable. Example:

```js
const got = require('got');

const instance = got.extend({
hooks: {
afterResponse: [
response => {
const {userData} = response.request.options;
userData.latestFetchedSite = response.url;
}
]
}
});

(async () => {
const userData = {
latestFetchedSite: ''
};

const response = await instance('https://example.com', {userData});

// Let's see our user data
console.log(userData.latestFetchedSite); // => https://example.com/

// `userData` won't be displayed here, because it's not enumerable.
// Of course, you can access it in the following way: response.request.options.userData
console.log(response.request.options);
})();
```

###### responseType

Expand Down

0 comments on commit c82447c

Please sign in to comment.