Skip to content

Allow setting method in the client instance #127

@gustavnikolaj

Description

@gustavnikolaj

This http client looks really nice and approachable. :-)

I love the idea of partially configuring the client ahead of time, and having the ability to e.g. only add the path of the URL at the actual callsite. There's one thing I'd wish it would do differently - I am unable to set the method at the call-site:

const myHttpClient = bent('https://example.com', 'json', 200);

const myGetRequest = await myHttpClient('GET', '/api/entity/42');
const myPostRequest = await myHttpClient('POST', '/api/entity', { "name": "My new Entity" });

I can achieve something like the above, by hacking around it, but it feels less clean :-)

const clientOptions = ['https://example.com', 'json', 200];
const myHttpClient = {
  get: bent(...clientOptions, 'GET'),
  post: bent(...clientOptions, 'POST')
};

const myGetRequest = await myHttpClient.get('/api/entity/42');
const myPostRequest = await myHttpClient.post('/api/entity', { "name": "My new Entity" });

This is just a suggestion - please feel free to close the issue immediately if it isn't something you want to do. I'd love know your reasoning, if there's a good reason why you don't want to - but it's also alright if it's just a matter of taste :-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions