REST API Basics - 4 Things you Need to Know (2024)

A REST API is the most common standard used between Clients (a person or application) who want to access information from the web from Servers (application or database) who have access to that information.

REST API Basics - 4 Things you Need to Know (1)

An Application Programming Interface (API) is a way for two computers to talk to each other over the web. For example, a delivery app can use the Google Maps API to support location tracking instead of building one from scratch. Or a recipe website can use an AI model to suggest alternative recipes based on the same ingredients using the ChatGPT REST API.

An API that follows the REST standard is called RESTful. Here are good practices when designing and using a RESTful API using the example of a survey app.

  1. Basic format
  2. HTTP verbs
  3. URL endpoints
  4. Status codes

1. Basic format

The format of a RESTful API has three main components: 1) URL endpoint; 2) HTTP verb; and 3) Body.

URL endpoint:Is a URL link that represents the resources we want to access. Resources can be text, images, documents or any data entry. For example, example.com/surveys allows us to view or create survey templates and example.com/surveys/123/responses allows us to do the same for all responses of survey 123.

HTTP verb:Tells the server what we want to do with the URL endpoint resource. For example, a POST request means we want to create a new survey template and a GET request means we want to view an existing survey template.

Body message:Is an optional custom payload which contains a message with the properties and values we want to use to create or update a given resource.

For example, we want to create a new response for the survey 123 which we captured which includes a positive NPS score of 9, a short feedback message and the unique id of the respondent who gave the feedback.

// Request:POST example.com/surveys/123/responses// Body payload:{ survey_id: 123, nps_score: 9, feedback: "love the service", respondent_id: 42}

The server receives the HTTP request and returns a response that includes a HTTP status code and a response usually in JSON format. Here is an example request and response to a REST API server asking to read all the responses for survey 123:

Request:

GET http://example.com/surveys/123/responses

Response:

// HTTP status code: 200{ survey_id: 123, survey_title: "nps onboarding survey", responses: [ { response_id: 42, nps_score: 9, feedback: "love the service", respondent_id: 42 } ... ]}

2. HTTP verbs

There are 5 basic verb commands when making a HTTP request:

  • GET: make a read only request to view either a single or list of multiple resources
  • POST: create a new resource based on the payload given in the body of the request
  • DELETE: destroy the given resource based on the id provided
  • PUT: update the entire fields of the resource based on the given body of the request or create a new one if not already exist
  • PATCH: update only the fields of the resource if it exists

Most applications and resources will support all these commands. This is commonly referred to as a CRUD application:

AcronymHTTP verb
CreatePOST
ReadGET
UpdatePUT & PATCH
DeleteDELETE

3. URL endpoints

A URL endpoint in a RESTful API represents any given object, data or service the API can access. For example, example.com/surveys represents the data for all survey templates and example.com/surveys/123/responses the data for all responses of a given survey.

URL endpoints should be grouped as pluralised nouns around the business data and objects and not verbs. For example, example.com/surveys and not example.com/getAllSurveys.

URL endpoints should include the unique identifier as a path after the pluralised noun when viewing, updating or deleting a single item. For example, example.com/surveys/123.

Organise URL collections in a logical hierarchy based on relationships. For example, users are most likely to access responses to a given survey template. This would be represented as example.com/surveys/123/responses.

Here is a summary of good practice URL endpoints and how they interact with HTTP verbs:

URL endpoint resourceGETPOSTPUTDELETE
/surveysRetrieve all surveysCreate a new surveyBulk update surveys (not advised)Remove all surveys (not advised)
/surveys/123Retrieve the details for survey 123ErrorUpdate the details of survey 123 if it existsRemove survey 123
/surveys/123/responsesRetrieve all responses for survey 123Create a new response for survey 123Bulk update responses for survey 123 (not advised)Remove all responses for survey 123 (not advised)
/responses/42Retrieve the details for response 42ErrorUpdate the details of response 42 if it existsRemove response 42

4. Status codes

Upon receiving a HTTP request in the basic RESTful format the server will return a HTTP status code along with any optional JSON payloads. Here are the most common HTTP status codes and their meaning:

Status codeMeaning
200 OKRequest was successful.
301 Moved PermanentlyFor SEO purposes when a page has been moved and all link equity should be passed through.
401 UnauthorizedServer requires authentication.
403 ForbiddenClient authenticated but does not have permissions to view resource.
404 Not FoundPage not found because no search results or may be out of stock.
500 Internal Server ErrorServer side error. Usually due to bugs and exceptions thrown on the server side code.
503 Server UnavailableServer side error. Usually due to a platform hosting, overload and maintenance issue.

Get future posts with actionable tips in under 5 minutes and a bonus cheat sheet on '10 Biases Everyone Should Know'.

Your email stays private. No ads ever. Unsubscribe anytime.

REST API Basics - 4 Things you Need to Know (2024)
Top Articles
How to Obliterate Yourself in Risk of Rain 2
Value of Gold Sacagawea One Dollar Coins | Sacagawea Price Guide
Ffxiv Palm Chippings
Chicago Neighborhoods: Lincoln Square & Ravenswood - Chicago Moms
Sandrail Options and Accessories
Kansas Craigslist Free Stuff
Kris Carolla Obituary
The Powers Below Drop Rate
Embassy Suites Wisconsin Dells
Evita Role Wsj Crossword Clue
Strange World Showtimes Near Amc Braintree 10
10 Great Things You Might Know Troy McClure From | Topless Robot
R/Afkarena
Seattle Rpz
Missed Connections Dayton Ohio
Uky Linkblue Login
Craigslist Red Wing Mn
Shasta County Most Wanted 2022
Sadie Proposal Ideas
Sizewise Stat Login
Ein Blutbad wie kein anderes: Evil Dead Rise ist der Horrorfilm des Jahres
Morristown Daily Record Obituary
Craigslist Personals Jonesboro
Kirk Franklin Mother Debra Jones Age
Craigslist Comes Clean: No More 'Adult Services,' Ever
Mississippi Craigslist
Vadoc Gtlvisitme App
10 Best Quotes From Venom (2018)
Barbie Showtimes Near Lucas Cinemas Albertville
Gridwords Factoring 1 Answers Pdf
Memberweb Bw
How to Destroy Rule 34
School Tool / School Tool Parent Portal
Solemn Behavior Antonym
Vanessa West Tripod Jeffrey Dahmer
Oxford Alabama Craigslist
Best Restaurant In Glendale Az
Fototour verlassener Fliegerhorst Schönwald [Lost Place Brandenburg]
Craigslist Tulsa Ok Farm And Garden
Busted Newspaper Campbell County KY Arrests
Rhode Island High School Sports News & Headlines| Providence Journal
Craigslist Food And Beverage Jobs Chicago
Vérificateur De Billet Loto-Québec
Funkin' on the Heights
Xre 00251
Dobratz Hantge Funeral Chapel Obituaries
Canonnier Beachcomber Golf Resort & Spa (Pointe aux Canonniers): Alle Infos zum Hotel
Compete My Workforce
OSF OnCall Urgent Care treats minor illnesses and injuries
Generator für Fantasie-Ortsnamen: Finden Sie den perfekten Namen
Ranking 134 college football teams after Week 1, from Georgia to Temple
Latest Posts
Article information

Author: Merrill Bechtelar CPA

Last Updated:

Views: 5845

Rating: 5 / 5 (50 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Merrill Bechtelar CPA

Birthday: 1996-05-19

Address: Apt. 114 873 White Lodge, Libbyfurt, CA 93006

Phone: +5983010455207

Job: Legacy Representative

Hobby: Blacksmithing, Urban exploration, Sudoku, Slacklining, Creative writing, Community, Letterboxing

Introduction: My name is Merrill Bechtelar CPA, I am a clean, agreeable, glorious, magnificent, witty, enchanting, comfortable person who loves writing and wants to share my knowledge and understanding with you.