You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current http api is not yet very user friendly. For example: if you want to post JSON data, you manually need to do the serialization and set the Content-Type header.
I think this api would be greatly improved, if it would implement certain concepts from the Node.js request library.
Because of method signature limitations of Go (no default params etc), I would make all the methods (get, post, request etc) take a single params object as parameter. E.g. http.request({ method: 'GET', url: 'http://test.com', ... })
baseUrl
qs - object containing querystring values to be appended to the url
body - entity body for PATCH, POST and PUT requests.
form - when passed an object or a querystring, this sets body to a querystring representation of value, and adds Content-type: application/x-www-form-urlencoded header.
json - sets body to JSON representation of value and adds Content-type: application/json header.
defaults method - creates a new instance of the HTTP API with defaults configured. Any param can be set to a default value.
There are more things that could be added, but I consider these as the most important. It is important to be able to easily do JSON and form requests.
We should try to prevent that people need to write utilities to do such basic things themselves.
The text was updated successfully, but these errors were encountered:
I like this as well, but I'm not sure if auto parsing the response as JSON if json is set is necessary. I mean, isn't this covered by the current Response API with the json() method (as I guess the alternative would be to return the same when body is accessed or json() are called)?
@robingustafsson good point. When I wrote this I hadn't yet found out about response.html() and response.json(). I think we should add some examples about those (the OO practice of having methods on returned data, is less common in the Javascript world).
I removed that part from the proposal.
The current http api is not yet very user friendly. For example: if you want to post JSON data, you manually need to do the serialization and set the
Content-Type
header.I think this api would be greatly improved, if it would implement certain concepts from the Node.js request library.
get
,post
,request
etc) take a single params object as parameter. E.g.http.request({ method: 'GET', url: 'http://test.com', ... })
baseUrl
qs
- object containing querystring values to be appended to the urlbody
- entity body for PATCH, POST and PUT requests.form
- when passed an object or a querystring, this sets body to a querystring representation of value, and adds Content-type: application/x-www-form-urlencoded header.json
- sets body to JSON representation of value and adds Content-type: application/json header.defaults
method - creates a new instance of the HTTP API with defaults configured. Any param can be set to a default value.There are more things that could be added, but I consider these as the most important. It is important to be able to easily do JSON and form requests.
We should try to prevent that people need to write utilities to do such basic things themselves.
The text was updated successfully, but these errors were encountered: