REST and status codes
Design predictable resources and use status codes that clients can act on.
What you will be able to do
- Name resources with nouns, not verbs.
- Use plural collection paths.
- Return 201 plus a Location header on create.
- Use 422 for validation errors and include field details.
In plain English
REST models resources as URLs and uses HTTP methods for actions. Return 200 for reads, 201 for creation, 204 for no content, 400 for malformed input, 401 for unauthenticated, 403 for forbidden, 404 for missing and 422 for validation failures.
POST /api/courses HTTP/1.1
Content-Type: application/json
{"title":"CSS Grid"}
HTTP/1.1 201 Created
Location: /api/courses/css-grid
Content-Type: application/jsonYour turn
EasyReturn 201 on create
Which status code should a successful resource creation return?
HTTP · starter
status =Check your understanding before moving on.
Knowledge checkQuestion 1
Which status code means the request was understood but validation failed?
Select an answer to continue
Study tools
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.