RESTful Web APIs: an overview
REST is the standard most web APIs follow, with one HTTP verb (GET, POST, PUT, DELETE) for each CRUD operation.
Apprentice · Spring Boot · REST API · Updated
In 2000 a web standard was developed for handling API requests over the HTTP protocol. The standard is named REpresentational State Transfer, or REST. The REST standard defines a set of rules to build lightweight, and scalable web APIs.
The REST standard defines separate verbs for all CRUD operations.
- GET is used like a SELECT statement to return an existing resource
- POST is used like an INSERT statement to add a new resource
- PUT is used like an UPDATE statement to modify an existing resource
- DELETE is used like a DELETE statement to delete a resource
Do it: match each HTTP verb to its SQL statement
A new teammate knows SQL well but is new to REST. To help them read the API's request log, write a method that gives the SQL statement each HTTP verb works like, as the list above pairs them.
The method gets one value:
verb: an HTTP verb from the log, aString, in capitals, such as"GET".
verb |
Works like |
|---|---|
GET |
"SELECT" |
POST |
"INSERT" |
PUT |
"UPDATE" |
DELETE |
"DELETE" |
For example, a GET returns an existing resource, the way a SELECT does, so sqlFor("GET") returns "SELECT".
Your job: write the method sqlFor(String verb) so it returns the SQL statement's name, a String, as the table says.
- Each of the four verbs returns its statement from the table.
- Any other verb, such as
"PATCH", returns"Unknown".
Practiced live on the lesson page: write the Java right there and check it.