Restlet POST using JSON

json, post, restlet

Solution

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

Problem

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

Original source