1. HTTP, Request Methods and Response Codes
Request Methods
| Method | Action |
|---|---|
| GET | Retrieve resource, no modification on server |
| POST | Create resource |
| PUT | Update resource |
| DELETE | Delete resource |
MDN Web Docs – HTTP request methods
Response Status Codes
| Code | Action |
|---|---|
| 200 OK | Request successful |
| 201 CREATED | Request successful and resource has been created |
| 404 NOT FOUND | Resource not found |
| 405 METHOD NOT ALLOWED | Request method is not allowed for the resource |
MDN Web Docs – HTTP response status codes
2. Specifying Allowed Request Method for Controller Mapping
Curl Command
curl -X POST localhost:8080/people/create/Alice/65
3. Adding a Request Body
Curl Command with Request Body
curl -iX POST --header "Content-Type: application/json" --data '{"name": "Alice", "age": 53}' localhost:8080/people/create/
4. Adding GET(individual resource), PUT and DELETE Mappings to Controller
As we add functionality to create, read, update and delete a resource to a controller, it becomes a so called CRUD Controller.
Top comments (0)