-
Notifications
You must be signed in to change notification settings - Fork 841
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 method to allow posting stringified json contents #100
Conversation
FWIW, I realized that you can do this with the current code base by specifying the contentType and using However, I still would be nice to have this convenience method. |
throws HttpRequestException { | ||
contentType(CONTENT_TYPE_JSON); | ||
try { | ||
openOutput(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could just call send
here instead which would make this method a little simpler:
contentType(CONTENT_TYPE_JSON);
send(jsonString);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a PR worth adding? If so, I'll update the code. Otherwise, no offense taken.
When I first submitted it, I didn't realize that it could be sent using a combination of 'contentType' and send
and thought I would need to openOutput
myself. form
caught my attention and got fixated on that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a PR worth adding?
Yeah, I think so, given how common working with JSON is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright - change has been made.
* @return this request | ||
* @throws HttpRequestException | ||
*/ | ||
public HttpRequest json(final String jsonString) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be final CharSequence
to be consistent with the signature of the other helpers.
Closing this as it is super stale. |
This is a one-method addition to allow for sending a json body in the request. It doesn't add any dependencies since the signature just takes the stringified json.