Skip to content

Instantly share code, notes, and snippets.

@atesibrahim
Last active July 18, 2022 11:19
Show Gist options
  • Save atesibrahim/ba8afef72335a3611c9e072eede74e2c to your computer and use it in GitHub Desktop.
Save atesibrahim/ba8afef72335a3611c9e072eede74e2c to your computer and use it in GitHub Desktop.
RESTful example
@RestController
@RequestMapping("books")
public class BookController {
@Autowired
private BookService bookService;
@GetMapping("/{id}")
public BookDto getById(@PathVariable(name = "id") Integer id) {
return bookService.getById(id);
}
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public void save(@RequestBody BookDto bookDto) {
bookService.create(bookDto);
}
@PutMapping("/{id}/stock")
public BookDto updateStock(@PathVariable(name = "id") Integer id, @RequestBody Stock stock){
return bookService.updateStock(id, stock);
}
@DeleteMapping("/{id}")
@ResponseStatus(HttpStatus.NO_CONTENT)
public BookDto delete(@PathVariable(name = "id") Integer id) {
return bookService.delete(id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment