A Practical Introduction to REST API Design

  1. The Data — The list of emails and their details such as author, subject, snippet, date.
  2. The Presentation — HTML, CSS, Javascript used to render this list of emails
  1. URL: This is the URL we send the request to. For example, https://<mywebsite.com>/users
  2. Method: All HTTP requests contain a method. When you type a URL into a browser, the method used by default is GET. The most commonly used HTTP verbs (methods) are GET (retrieve), POST (create), PUT (update), DELETE (delete).
  3. Body: An HTTP request can contain a body. This is typically used to send content, for example the username/password during login, or the user’s profile information when creating / updating the user.
  4. Query Parameters: When you search for something on Google/Bing, you will see this in the URL — /search?q=rest . Here q=rest is a query parameter, where q is the key and rest is the value.
return users
GET <mywebsite>/users/
When creating REST APIs for a collection of items, limit the URL to just the collection name, and mention the action in the verb (method).
Request
Response
users.add(newUser)
Method: POST 
URL: /users/
Body: {"name": "John Brown", "occupation": "Carpenter"}
Header: Content-Type: application/json
Any data that needs to be sent to the request goes as the body, with a header Content-Type that defines the format of the body (JSON/XML etc).
return users.single { it.userId == 17 }
Method: GET 
URL: /users/17
Method: GET 
URL: /users/:userId
Method: DELETE
URL: /users/:userId
Within a collection, access a particular element by its unique identifier. Use the method to define what needs to be done with it.
GET Request to get user with id 12
PUT Request to update the user’s first and last names
DELETE Request to delete user with Id 12
articles.findById(:articleId).comments.findById(:commentId)
articles/:articleId/comments/:commentIdExample: articles/17/comments/88
Sub-collections are denoted by relative paths in queries. 
return users.find { it.points == 0 } 
Method: GET
URL: /users?points=0&active=true
Additional information needed to process a request to retrieve information that is not a sub-collection goes as a query parameter. 
  1. When creating REST APIs for a collection of items, limit the URL to just the collection name, and mention the action in the verb (method). This action includes GET (retrieve), POST (create), DELETE (delete), PUT (update).
  2. Any data or content that needs to be sent as a part of the request goes as the body, with a header Content-Type that defines the format of the body (JSON/XML etc).
  3. Within a collection, access a particular element by its unique identifier such as id or name.
  4. Sub-collections are denoted by relative paths in queries.
  5. Additional information needed to process a request to retrieve information that is not a sub-collection goes as a query parameter.

--

--

--

Educator, Founder @ Interleap

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Top Web 3.0 Developed Apps You Must Know About

An Example of Why You Should Write Tests For Bugs Before Fixing The Problem

How to create a Firebase Cloud Function with static outbound IP

How to have multiple Microsoft Teams Instances (Windows)

✨Team highlight: say hello to Jayden!

Creating an Application Environment using Anaconda Navigator

How I Integrated spring boot application with Crowd

KintoHub 0.5.0

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Abhinav

Abhinav

Educator, Founder @ Interleap

More from Medium

SOLID Principles in OOP

JS with SOLID Principles

S.O.L.I.D Principles

A brief description of OOP in java