Short story: I wonder if the OTP team and community would be interested in refactorings of inets, specifically httpc and httpd. I think it could be done in stages and an initial pass would be on the API’s to be more user friendly.
I won’t have time to take part in something like this for many many months but it has been on my mind off and on for so long I thought I’d better get it out.
I think it is great and important to have the http client/servers available in OTP, and httpc in particular has improved a lot over the years, and know they will never be able to completely remove need for third party alternatives, but I think a little love would go a long ways.
Below is just what was on top of my mind and is not a deep dive in any sense.
httpc
Awkward API:
inets
starts httpc
profiles but then any options have to be added with httpc:set_options
.
request(Method, Request, HttpOptions, Options, Profile)
– Why is Request
a tuple instead of something like httpc:request(Method, URL, Headers)
or httpc:get(Url, Headers)
Responses are currently large tuples:
{{http_version(), status_code(), reason_phrase()}, headers(), body()}
A map would be nicer:
#{status_code := status_code(),
headers := headers(),
Could also have a Request
record or map that holds the middlewares to call, base url, headers, options and makes re-usability easier:
BasicAuth = fun(Request, Next) -> Next(httpc_request:add_header(Request, ...)) end,
Request = httpc_request:new(#{base_url => "http://google.com", middlewares => [BasicAuth]}),
Response = httpc:get(Request, #{url => "/search"}),
Instrumentation: As shown in the above example, I’d like to see middlewares of some sort supported so things like distributed tracing and metrics collection could be more easily supported.
httpd
I’m less familiar with httpd
but recall my uses have always felt frustrating to get setup. This may mean it is either just me or the need for documentation geared more towards usage similar to other Erlang web servers.
But questions to answer first are:
- Is there interest?
- How would backwards compatibility be handled?
- Have none?
- All new modules/applications?
- Maybe it would be lower level than httpc/httpd and those made to use the new modules/applications?
- I specifically skipped questions like pooling to start with and maybe this would be the answer to that: There would be no pooling support, the new client (maybe server too?) would be single connection based and pooling have to happen by a third party library. So
inets
profile
based process/connection handling would remain.
In that order