java - Heroku JAX-RS POST -
scenario:
recently, our team created application on heroku. got of our environments set inside eclipse , became familiar git. able change code , @ least see manipulate http request return results wanted. mission now, try post working.
right now, have simple testservice can retrieve json objects doing this: myurl.com/services/test/test1 , return json object:
{ "name": "test1", "test": 100 }
code:
@path("/test") public class testservice { @get @produces(mediatype.application_json) public testobject get() { return new testobject(); } @get @path("/{name}") @produces(mediatype.application_json) public testobject get(@pathparam("name") string name) { return testobject.getobject(name); } @post @path("/post") @consumes(mediatype.application_json) public void post(final testobject object) { testobject.postobject(object.getname(), object); } }
question:
a) how set code http post request?
b) how request above request?
a) if right, you're looking how set post method on service. try this, have right now. have @ return type javax.ws.rs.core.response.
@post @path("/post") @consumes(mediatype.application_json) @produces(mediatype.application_json) public static response post( string testobjectasjson){ testobject testobject = testobjectasjson.toentity; //some json deserialization function //do testobject //return status of 200 client return response.status(200).build; }
if want process testobject , return modified 1 try this:
string testobjectasjson = testobject.tojson; //some json conversion method return response.status(200).entity(testobjectasjson).build;
b) testing request e.g. use chrome://restclient/content/restclient.html in firefox. (maybe have add first under add-ons). there can send post requests service.
Comments
Post a Comment