DEV Community

Cover image for Request/Response Part 2: HTTP & The CRUD Controller
Software Development Academy
Software Development Academy

Posted on • Updated on

Request/Response Part 2: HTTP & The CRUD Controller

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

GitHub Repo Tag

Curl Command

curl -X POST localhost:8080/people/create/Alice/65
Enter fullscreen mode Exit fullscreen mode

3. Adding a Request Body

GitHub Repo Tag

Curl Command with Request Body

curl -iX POST --header "Content-Type: application/json" --data '{"name": "Alice", "age": 53}' localhost:8080/people/create/
Enter fullscreen mode Exit fullscreen mode

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.

GitHub Repo Tag



Previous article |
Next article

Top comments (0)