Back-End Development RESTful API Design and Development 1 — Questions and Answers
Question 1: Which HTTP method is idempotent and should be used to fully replace a resource?
- POST
- PUT (Correct answer)
- PATCH
- DELETE
Correct answer: PUT
PUT is idempotent, meaning multiple identical requests produce the same result, and it fully replaces the target resource.
Question 2: What HTTP status code should a REST API return when a resource is successfully created?
- 200 OK
- 201 Created (Correct answer)
- 204 No Content
- 202 Accepted
Correct answer: 201 Created
201 Created is the standard response for a successful POST request that results in the creation of a new resource.
Question 3: Which of the following is a constraint of REST architecture?
- Stateful sessions
- Mandatory XML responses
- Statelessness (Correct answer)
- Fixed URL structure
Correct answer: Statelessness
Statelessness means each HTTP request must contain all the information needed to process it, with no session stored on the server.
Question 4: What does HATEOAS stand for in REST API design?
- Hypertext As The Engine Of Application State (Correct answer)
- HTTP And Transfer Engine Of Application Services
- Hypertext API Transfer Engine Of Async Services
- HTTP Access To External Object Application State
Correct answer: Hypertext As The Engine Of Application State
HATEOAS is a REST constraint where the API response includes hyperlinks that guide the client to available actions.
Question 5: Which HTTP status code indicates that the client is not authorized to access a resource (authentication required)?
- 400 Bad Request
- 403 Forbidden
- 401 Unauthorized (Correct answer)
- 404 Not Found
Correct answer: 401 Unauthorized
401 Unauthorized means the request lacks valid authentication credentials, prompting the client to authenticate.
Question 6: In REST API versioning, which approach embeds the version number in the URL path?
- Header versioning
- Query parameter versioning
- URI versioning (Correct answer)
- Content negotiation
Correct answer: URI versioning
URI versioning places the version number directly in the URL path, such as /api/v1/users, making it highly visible and cacheable.
Which HTTP method is idempotent and should be used to fully replace a resource?