From 5230ffcf6e785836a94dae86c831c0cb6365a4d7 Mon Sep 17 00:00:00 2001 From: Gregor Date: Sat, 20 Oct 2018 12:56:18 -0700 Subject: [PATCH] docs(README): amend .defaults() usage example --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index 95b87a84..7d72da9e 100644 --- a/README.md +++ b/README.md @@ -200,6 +200,25 @@ request(myEndpoint(`GET /orgs/:org/repos`)) You can call `.defaults()` again on the returned method, the defaults will cascade. +```js +const myProjectEndpoint = endpoint.defaults({ + baseUrl: 'http://github-enterprise.acme-inc.com/api/v3', + headers: { + 'user-agent': 'myApp/1.2.3' + }, + org: 'my-project' +}) +const myProjectEndpointWithAuth = myProjectEndpoint.defaults({ + headers: { + authorization: `token 0000000000000000000000000000000000000001` + } +}) +``` + +`myProjectEndpointWithAuth` now defaults the `baseUrl`, `headers['user-agent']`, +`org` and `headers['authorization']` on top of `headers['accept']` that is set +by the global default. + ## Special cases ### The `data` parameter – set request body directly