コード例 #1
0
 // 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());
 }
コード例 #2
0
 // curl -X GET -i http://localhost:8080/todo-app/api/todo/{id}
 @RequestMapping(value = "todo/{id}", method = RequestMethod.GET)
 @ResponseStatus(HttpStatus.OK)
 @ResponseBody
 public Todo todo(@PathVariable String id) {
   Todo todo = todoService.get(id);
   if (todo == null) throw new NotFoundException();
   return todo;
 }
コード例 #3
0
 // 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());
 }
コード例 #4
0
 // curl -X DELETE -i http://localhost:8080/todo-app/api/todo/{id}
 @RequestMapping(value = "todo/{id}", method = RequestMethod.DELETE)
 @ResponseStatus(HttpStatus.NO_CONTENT)
 public void delete(@PathVariable String id) {
   todoService.delete(id);
 }
コード例 #5
0
 // curl -X GET -i http://localhost:8080/todo-app/api/todo
 @RequestMapping(value = "todo", method = RequestMethod.GET)
 @ResponseStatus(HttpStatus.OK)
 @ResponseBody
 public Todos todos() {
   return new Todos(todoService.getAllTodos());
 }