Level Up Coding

Coding tutorials and news. The developer homepage gitconnected.com && skilled.dev && levelup.dev

Follow publication

Deep Dive into REST: Key Concepts, Terms, Best Practices with Examples.

Rahul Beniwal
Level Up Coding
Published in
7 min readJan 14, 2024

What is REST?

Deeper Dive

URN (Uniform Resource Name): A URN is a type of URI that identifies a resource by name in a particular namespace but doesn’t provide information on how to locate the resource. Eg -> urn:isbn:0451450523

URL (Uniform Resource Locator): A URL is a specific type of URI that includes information on how to locate a resource. It provides the means to access the resource through a specific protocol and location details.

Examples

GET /articles/123
{
"id": 123,
"title": "RESTful Principles",
"content": "An in-depth explanation of RESTful principles.",
"author": "John Doe"
}
PUT /articles/123
Content-Type: application/json

{
"id": 123,
"title": "RESTful Principles Explained",
"content": "A comprehensive guide to understanding RESTful principles.",
"author": "John Doe"
// Updated article details
}

Example

GET /articles
HTTP/1.1 200 OK
Content-Type: application/json

{
"articles": [
{
"id": 123,
"title": "RESTful Principles Explained",
"author": "John Doe"
// Other article details
},
// Additional articles
],
"links": [
{
"rel": "next",
"href": "/articles?page=2"
},
// Other links
]
}

Best Practices for Designing RESTful APIs

GET /books/123
{
"id": 123,
"title": "The Hitchhiker's Guide to the Galaxy",
"author": "Douglas Adams",
"published_year": 1979,
"links": [
{
"rel": "self",
"href": "/books/123"
},
{
"rel": "edit",
"href": "/books/123/edit"
},
{
"rel": "delete",
"href": "/books/123/delete"
}
]
}

Real-World Examples of RESTful Concepts

GET: Retrieve user profile information (GET /users/{user_id}).
POST: Create a new user profile (POST /users).
PUT: Update an existing user profile (PUT /users/{user_id}).
DELETE: Remove a user profile (DELETE /users/{user_id}).
1. Client specifies the desired representation in the Accept header (Accept: application/json).
2. Server responds with the requested representation.

Conclusion

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Written by Rahul Beniwal

I can help you master Python | Backend | System Design | Django | Rust | Computer Science | Databases | Making complex concepts clear and accessible with code

No responses yet

Write a response