Got: Endpoint prefix / default config

Created on 8 Jun 2016  路  3Comments  路  Source: sindresorhus/got

I think it would be cool if there was an easy way to do something like:

var github = got.endpoint('https://api.github.com', {agent: ...});

// github has the same API as got, except you don't need the base path
// and certain default options (i.e. `agent`) are already defined
github('/foo', {});

This main advantage would be for testing:

function MyGitHubApi() {
  this._gh = got.endpoint('https://api.github.com', {agent: ...});
}

MyGitHubApi.getFoo = function () {
  return this._gh('/foo');
}

// later in tests:

var api = new MyGitHubApi();
api._gh.override('http://localhost:3000');

Most helpful comment

We have a lot of files, that just export got with default values. I would love to see a package got-api with some sweet stuff for generating cool API wrappers.

All 3 comments

We have a lot of files, that just export got with default values. I would love to see a package got-api with some sweet stuff for generating cool API wrappers.

Ability to add new options would be cool too.

Here it comes: #503

Was this page helpful?
0 / 5 - 0 ratings

Related issues

erfanium picture erfanium  路  3Comments

f-mer picture f-mer  路  4Comments

alvis picture alvis  路  3Comments

dAnjou picture dAnjou  路  3Comments

alanzhaonys picture alanzhaonys  路  4Comments