socketry / async-http

MIT License
320 stars 46 forks source link

Kwargs instead of positional args #49

Closed swrobel closed 3 months ago

swrobel commented 4 years ago

I'm curious why the decision was made to take positional, rather than keyword args in a modern library like this.

internet.post("https://httpbin.org/anything", body: body)

seems preferable to

internet.post("https://httpbin.org/anything", nil, body)
ioquatix commented 4 years ago

Positional args were at the time slightly more efficient and predictable than kwargs, but I'd be open to changing this if you think there is a significant improvement to interface ergonomics.

ioquatix commented 3 years ago

I've changed Async::HTTP::Client and Async::HTTP::Server to use keyword arguments.

I'm not sure we can easily change these methods without breaking a ton of stuff.

ioquatix commented 2 years ago

If we think the ergonimics outweighs the overhead, something like this can work:

def get(_headers = nil, _body = nil, headers: _headers, body: _body)
  # ...
end

and be backwards compatible. As long as the performance cost is insignificant, I'd be willing to accept this for the def get / post / patch convenience methods for Async::HTTP::Internet (but probably not call).

ioquatix commented 3 months ago

Okay, this is now supported.

See https://socketry.github.io/protocol-http/releases/index#request%5B%5D-and-response%5B%5D-keyword-arguments for details. It works for all methods including Internet#call.