Restlet POST using JSON

Porton picture Porton · Jan 9, 2010 · Viewed 29.2k times · Source

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

Thanks

Answer

Bruno picture Bruno · Jun 25, 2010

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:

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