Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POST Requests with raw post data #37

Closed
niklas88 opened this issue Sep 3, 2015 · 3 comments
Closed

POST Requests with raw post data #37

niklas88 opened this issue Sep 3, 2015 · 3 comments

Comments

@niklas88
Copy link

niklas88 commented Sep 3, 2015

Maybe I'm missing something but I couldn't find a way to do a post request with a custom content-type and raw body which is needed for many REST APIs that expect e.g. JSON in a POST body.

@whoshuu
Copy link
Contributor

whoshuu commented Sep 3, 2015

You're actually right, there's no way to upload raw data with POST/PUT/PATCH. This is an oversight, I'll have to get this down in 1.2, but it'll be pretty high priority. In the meantime, there is a way to set the content-type, but it requires you to go through the header. You have to add a Header{{"content-type"}, {"application/json"}} to your request call.

While we're on the subject, what are your thoughts on providing a json library (I'm thinking Niels Lohmann's library)? This would let me do things like accept a Json object and set the header automatically.

@whoshuu
Copy link
Contributor

whoshuu commented Sep 3, 2015

For now, I'm going to limit the scope of this to just providing an API for setting a raw data type for a request.

@niklas88
Copy link
Author

niklas88 commented Sep 3, 2015

I personally think that adding json is out of the scope of a HTTP library. Honestly I'm a big fan of the HTTP package of Go https://golang.org/pkg/net/http/ (by the way that implements all of HTTP itself and I find it to be pretty clean too) and that's also pretty clear on staying in the HTTP realm.

Also when cpr supports raw bodys either with it's own Body type or directly as string (this should probably be kept in sync with response.text / response.body) using json with it is absolutely trivial so the gain in my opinion isn't too big.

whoshuu added a commit that referenced this issue Sep 27, 2015
References #37
whoshuu added a commit that referenced this issue Sep 27, 2015
whoshuu added a commit that referenced this issue Sep 27, 2015
whoshuu added a commit that referenced this issue Sep 27, 2015
whoshuu added a commit that referenced this issue Sep 27, 2015
whoshuu added a commit that referenced this issue Sep 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants