I am using sitebricks-client to interact with REST APIs in Java. I need to do a POST with a non-empty body. How do I do that in sitebricks?
How to post body in sitebricks-client?
275 Views Asked by pathikrit At
2
I am using sitebricks-client to interact with REST APIs in Java. I need to do a POST with a non-empty body. How do I do that in sitebricks?
You have not specified what kind of request body you are trying to post. If you are trying to send a String with a Content-Type of "text/plain", then the following should work:
If you are trying to send data of a particular type that you have already serialized to a String, you can set the Content-Type header manually:
If you have a Map containing data that you would like to send to the server with a Content-Type of "application/json", then something like this might be up your alley:
There are two important points to pay attention to in the examples above:
post
method should be of the type passed to thetransports
method.over
method determines the default value of the Content-Type header and the way in which the value passed to thepost
method is serialized. The class should be a subclass ofcom.google.sitebricks.client.Transport
, and you will probably want to choose one of the classes found in thecom.google.sitebricks.client.transport
package.