public SampleOidEntity read(Request request, Response response) { String id = request.getHeader(Constants.Url.SAMPLE_ID, "No resource ID supplied"); SampleOidEntity entity = service.read(Identifiers.MONGOID.parse(id)); // enrich the resource with links, etc. here... HyperExpress.bind(Constants.Url.SAMPLE_ID, Identifiers.MONGOID.format(entity.getId())); return entity; }
public void update(Request request, Response response) { String id = request.getHeader(Constants.Url.SAMPLE_ID, "No resource ID supplied"); SampleOidEntity entity = request.getBodyAs(SampleOidEntity.class, "Resource details not provided"); entity.setId(Identifiers.MONGOID.parse(id)); service.update(entity); response.setResponseNoContent(); }
public SampleOidEntity create(Request request, Response response) { SampleOidEntity entity = request.getBodyAs(SampleOidEntity.class, "Resource details not provided"); SampleOidEntity saved = service.create(entity); // Construct the response for create... response.setResponseCreated(); // Bind the resource with link URL tokens, etc. here... TokenResolver resolver = HyperExpress.bind(Constants.Url.SAMPLE_ID, Identifiers.MONGOID.format(saved.getId())); // Include the Location header... String locationPattern = request.getNamedUrl(HttpMethod.GET, Constants.Routes.SINGLE_OID_SAMPLE); response.addLocationHeader(LOCATION_BUILDER.build(locationPattern, resolver)); // Return the newly-created resource... return saved; }
public void delete(Request request, Response response) { String id = request.getHeader(Constants.Url.SAMPLE_ID, "No resource ID supplied"); service.delete(Identifiers.MONGOID.parse(id)); response.setResponseNoContent(); }