How do I implement Restlet function which accepts JSON post? And how do I test this using curl?
Thanks
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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With