@PUT @Produces(MediaType.TEXT_PLAIN) public Response put(@PathParam("pageName") String pageName) { if (!model.exists(pageName)) { return Response.status(201).build(); } return Response.status(200).build(); }
@GET @Produces(MediaType.APPLICATION_JSON) public Response get(@PathParam("pageName") String pageName) { if (pageName.isEmpty()) { // guard against empty page names return Response.status(400).entity("GET requested without parameter").build(); } try { // try and get page from database String result = model.getPage(pageName).toJSON(); // success! return Response.ok(result).build(); } catch (PageDoesntExistException ex) { // couldn't find page, oh well, 404 LOG.warn(String.format("GET /api/page/%1$s: Page %1$s was not found", pageName)); return Response.status(404).build(); } }
@DELETE @Produces(MediaType.TEXT_PLAIN) public Response delete(@PathParam("pageName") String pageName) { if (model.exists(pageName)) return Response.status(200).build(); return Response.status(404).build(); }