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

Add JSON Post/Put support #16

Closed
cryptiklemur opened this issue Dec 29, 2017 · 4 comments
Closed

Add JSON Post/Put support #16

cryptiklemur opened this issue Dec 29, 2017 · 4 comments

Comments

@cryptiklemur
Copy link

Add support for posting/putting JSON.

Would be cool if we could just do this:

p({url: "some url", method: "POST", json: {foo: 'bar'});

Which would set the Content-Type and Accepts headers to application/json

@ethan7g
Copy link
Owner

ethan7g commented Dec 30, 2017

Thanks for the suggestion. This feature already kind of exists! The data phinOptions option is automatically JSON stringified if it's an object. (The Content-Type header isn't automatically set, but that's really easy for developers to do if they'd like.)

See the phinOptions type definition for more details.

@ethan7g ethan7g closed this as completed Dec 30, 2017
@matteocontrini
Copy link

matteocontrini commented Jan 21, 2018

@ethanent I think the Content-Type should be added automatically, I've just spent the last 20 minutes trying to understand why the server was ignoring my POST data...

@thelinuxlich
Copy link

Why close this issue? Any API sending JSON without these headers is totally wrong.

@ethan7g
Copy link
Owner

ethan7g commented Jan 1, 2019

@matteocontrini @thelinuxlich Thanks for the suggestion.

As of [email protected], the Content-Type header is defined automatically for JSON.stringify-ed request bodies. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants