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 method to allow posting stringified json contents #100

Closed
wants to merge 4 commits into from

Conversation

brendonparker
Copy link

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.

@brendonparker
Copy link
Author

FWIW, I realized that you can do this with the current code base by specifying the contentType and using send instead of form to send a String (CharSequence). I'm using the this here.

However, I still would be nice to have this convenience method.

throws HttpRequestException {
contentType(CONTENT_TYPE_JSON);
try {
openOutput();
Copy link
Owner

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);

Copy link
Author

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.

Copy link
Owner

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.

Copy link
Author

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) {
Copy link
Owner

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.

@brendonparker
Copy link
Author

Closing this as it is super stale.

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

Successfully merging this pull request may close these issues.

None yet

2 participants