RESTful Routes

Wendy Raven McNair
2 min readMay 18, 2021

--

http://andrewnikonchuk.com/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:
http://localhost:3000/songs

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
Rails Routes
Quiet on the Set… ACTION!

Sign up to discover human stories that deepen your understanding of the world.

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

--

--

No responses yet

Write a response