Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restlet POST using JSON

Tags:

json

post

restlet

How do I implement Restlet function which accepts JSON post? And how do I test this using curl?

Thanks

like image 597
Lydon Ch Avatar asked Jan 09 '10 11:01

Lydon Ch


1 Answers

With Restlet 2, you can either:

  • test the entity media-type compatibility in @Post acceptRepresentation(Representation entity):

    @Post public Representation acceptRepresentation(Representation entity) throws ResourceException { if (entity.getMediaType().isCompatible(MediaType.APPLICATION_JSON)) { // ... } // ... }

  • or use @Post with one or two parameters:

    @Post("json") Representation acceptAndReturnJson(Representation entity) { // ... }

See these links:

  • http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2585586 [edit: tigris.org was shutdown July 2020]
  • https://javadocs.restlet.talend.com/2.0/jee/api/org/restlet/resource/Post.html

(With Restlet 1, you would need to test the type of the entity.)

like image 70
Bruno Avatar answered Oct 25 '22 19:10

Bruno