// curl -X PUT -i http://localhost:8080/todo-app/api/todo/{id} -d // '{"text":"TODO Item Text","done":true}' @RequestMapping(value = "todo/{id}", method = RequestMethod.PUT) @ResponseStatus(HttpStatus.NO_CONTENT) public void update(@PathVariable String id, @RequestBody Todo todo) { Todo existing = todoService.get(id); if (existing == null) throw new NotFoundException(); existing.setText(todo.getText()); existing.setDone(todo.isDone()); }
// curl -X POST -i http://localhost:8080/todo-app/api/todo?text=TodoItem1 @RequestMapping(value = "todo", method = RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED) @ResponseBody public void create(@RequestParam String text, HttpServletRequest req, HttpServletResponse resp) { Todo todo = todoService.createNewTodo(text); StringBuffer url = req.getRequestURL().append("/{id}"); UriTemplate uriTemplate = new UriTemplate(url.toString()); resp.addHeader("location", uriTemplate.expand(todo.getId()).toASCIIString()); }