RESTful Routes

RESTful routes adhere to a standard guideline for creating URL addresses that respond to fetch requests. REST is an abbreviation of REpresentational Sate Transfer which basically refers to how computers communicate using an HTTP verb and a URL route.

I found the following from one of Flatiron’s Learnco lessons to be helpful in defining RESTful routes:

… a route that provides mapping from HTTP verbs (get, post, put, delete, patch) to controller CRUD actions (create, read, update, delete). Instead of relying solely on the URL to indicate what site to visit, a RESTful route depends on the HTTP verb and the URL.

When you click through a website, you are making requests. These requests use HTTP (Hyper Text Transfer Protocol) which is code that controls how browsers and servers talk to each other.

A typical communication includes the URL (Uniform Resource Locator) route:

and an HTTP verb method:
GET

A GET request is a request to get some kind of data. The URL route indicates what kind of data will be fetched. For example, to see a list of songs, the fetch request would include the following:

fetch(`http://localhost:3000/songs`, {
method: ‘GET’
})

A POST request is a request to add a new item to a list of items. For example, to add a new song to a list of songs, the fetch request would include the following:

fetch(`http://localhost:3000/songs`, {
method: ‘POST’
})

There are seven basic RESTful routes. They include four GET, a POST, a DELETE, and a PUT or PATCH.

NOTE Both PUT and PATCH change a specific item that already exists. However PUT changes the entire item while PATCH changes only a part of the item.

  1. GET: /songs
    see a list of all the songs
  2. GET: /songs/new
    see a form to create a new song
  3. GET: /songs/:id
    see a single specific song (from the list of songs)
  4. GET: /songs/:id/edit
    see a form to edit the data of a specific song
  5. POST: /songs
    add a new song to the list of songs
  6. DELETE /songs/:id
    delete a specific song (from the list of songs)
  7. PUT /songs/:id
    change the data of a specific song

-or-

PATCH /songs/:id
change the data of a specific song

NOTE The id refers to the unique assigned number each item has in the data base. This enables a single item (ex. song) to be referenced by its id number.

RESTful routes can be considered a form of communication between the browser and the server. The communication includes an HTTP verb that identifies the request type of operation and a URL route that identifies a path to the kind of data requested and on which to operate.

TRILOGY: Front End and Back End Communication

RESTful Routes

--

--

--

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

Recommended from Medium

UWP Application Singin, Release, Distribute, Deploy With Azure DevOps Pipeline

3+ Tips to Distinguish Good and Bad Locators

Getting started with Robot Framework + Selenium for automation testing (7) — Resource and scopes

Use Docker to Simplify Data Science Development Environments

Playing With VMs and Kubernetes

Calling Out A0 Devs

Automatically Fetch Facebook Page Events With Laravel Dusk

Setting up a free Ghost blog on Google Cloud Platform and Cloudflare

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
Wendy Raven McNair

Wendy Raven McNair

More from Medium

How to upgrade Zabbix Network Monitoring tools 5.4 from version 5.2/5.0

Using Disposable Password on Bitbucket

Back to Laravel Homestead from Sail / Docker

SE3050 -Application Frameworks Blog