Bootcamp
Search…
4.2.1: RESTful Routes
REST stands for REpresentational State Transfer and refers to a convention for what a given set of URL paths do and how they affect the data in an app.
Some of the following routes apply in an AJAX API context and some do not.
The URL path parameters are also assumed to be named exactly the same in Express.js.
The following table assumes a table (and thus Sequelize model) named with "photo". Note the pluralization.
URL
HTTP Verb
Action/Controller Method Name
Functionality
Format
SQL
/photos/
GET
index
Get/render a list of photos
JSON/HTML
SELECT
/photos/create
GET
createForm
Render a form to create a photo
HTML
n/a
/photos/create
POST
create
Accept a request to create a new photo
JSON/Form Submit
INSERT
/photos/:id
GET
show
Get/render a single photo
JSON/HTML
SELECT
/photos/:id/edit
GET
edit
Render a form to edit a photo.
HTML
SELECT
/photos/:id
PATCH/PUT
update
Accept a request to update a photo.
JSON/Form submit
UPDATE
/photos/:id
DELETE
destroy
Accept a request to delete a photo.
JSON/Form submit
DELETE
A RESTful naming convention assumes that the method names inside the controller are the same across multiple controllers, and that the context of the controller they are in. In this case the controller would be named after "photo".

Caveats

Of course, for every table in an app, it may not make sense to implement all seven of the URLs mentioned above. Or there may be far more than 7. REST simply gives a recommendation for thinking about how to format the routes that you do want, given that you have a DB table.
It is definitely not a prescription about how the app should work or what it should include.

Industry examples

  • Shopify uses the REST model in it's Admin API.

Further Reading