...

/

Category API: List all Categories and Edit a Category

Category API: List all Categories and Edit a Category

Learn how to list all the categories and edit a category.

List all category API

Next, we’ll create an API to list all the categories. Create a function, getCategories, in the controller, which will call the listCategories method in the service.

Press + to interact
@GetMapping("/")
public ResponseEntity<List<Category>> getCategories() {
List<Category> body = categoryService.listCategories();
return new ResponseEntity<>(body, HttpStatus.OK);
}
Press + to interact
public List<Category> listCategories() {
return categoryRepository.findAll();
}

That’s it. Once we’ve set everything up, creating a new API is ...