Skip to content

Instantly share code, notes, and snippets.

@AlexMercedCoder
Created June 7, 2023 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexMercedCoder/d0d396257387eb815d5f513a6a71471c to your computer and use it in GitHub Desktop.
Save AlexMercedCoder/d0d396257387eb815d5f513a6a71471c to your computer and use it in GitHub Desktop.
REST

REST

REspresentational State Transfer

What is Rest?

REST is an architectural pattern for designing API (Application Programming Interface).

Basically?

  • What routes should I make
  • What should those routes do

The Basics

Every application is going be made up of many

models/resources/entities

  • The units of data your application works with.

For example:

  • Blogs
  • Photos

As an example, tweet:

{
    "text": "STRING",
    "create_at": "TIMESTAMP",
    "updated_at": "TIMESTAMP"
}

The details of what properties a model has and their data types, is known as that models SCHEMA.

RESTFul Routes

The RESTFul routes are a blueprint of the routes and how they should to provide basic CRUD (CREATE, READ, UPDATE, DELETE)

All the routes are built around a path that is named after the model.

/tweet
NAME METHOD URL WHAT DOES IT DO
INDEX GET /tweet return a list of tweets
NEW GET /tweet/new render a page with a form to create a new tweet, submits to CREATE route
DESTROY DELETE /tweet/:id delete the specified tweet from the database
UPDATE PUT/PATCH /tweet/:id Receive info and update the specified tweet in the database
CREATE POST /tweet receive info from NEW form and create new tweet in database
EDIT GET /tweet/:id/edit render a page with a form to edit the specified tweet, submits to UPDATE to route
SHOW GET /tweet/:id render a page with the specified tweet

TO REMEMBER... THINK INDUCES

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment