RESTful API - CRUD Annotations

Slack Discussion Repositories https://github.com/terawarehouse/terawarehouse-catalog https://github.com/terawarehouse/terawarehouse-react We...


Slack Discussion

Repositories
We will now dissect the CategoryController class, which is annotated to expose a set of REST endpoints.

[open CategoryController.java]
@RestController - It’s basically just a @Controller with @ResponseBody. It is used to annotate the controller class to indicate that it supports REST. It comes with @RequestMapping to define class level REST properties such as the path and what media type is produced.

For swagger documentation we use @ApiOperation, @ApiParam, and @ApiResponses.

Here are the most commonly used REST annotations in reference to CRUD.
  • Create / Http Post / @PostMapping - Creates a new entity. It returns the entity with the auto-generated id.
  • Update / Http Put / @PutMapping - Updates an existing entity. It also returns the updated entity.
  • Find/List / Http Get / @GetMapping - Returns an entity.
  • Delete / Http Delete / @DeleteMapping - Deletes an entity
  • Patch / Http Patch / @PatchMapping - In general Put should send all the fields of an entity during an update while patch just sends a subset. But in general, we just use Put.
These are mostly the core annotations that you will use again and again. But it should not be a problem as it’s generally easy to get familiar with them.

To test endpoints, I have preferred a Postman collection which is available in src/test/resources.

Let’s do some testing!

[open Postman collection]

Run the tests manually one by one. Change the uid parameter by getting the uid returned from the newly created category.

Next, we will discuss how we can automate request validation.

COMMENTS

mas template
Name

amazon,1,angular,8,bigdata,2,business,1,course-spring,27,courses,6,database,4,docker,3,java,50,kafka,1,keycloak,4,microservices,5,mysql,1,neworking,1,nosql,2,php,1,pinned,2,react,3,server management,7,shared drive,1,spring,7,synology,1,troubleshooting,2,web,1,wordpress,1,
ltr
item
toztech: RESTful API - CRUD Annotations
RESTful API - CRUD Annotations
https://i.ytimg.com/vi/IzpG3JC22XI/0.jpg
https://i.ytimg.com/vi/IzpG3JC22XI/0.jpg
toztech
https://toztech.blogspot.com/2019/07/restful-api-crud-annotations.html
https://toztech.blogspot.com/
https://toztech.blogspot.com/
https://toztech.blogspot.com/2019/07/restful-api-crud-annotations.html
true
2554149350007112447
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content