Skip to main content

RESTful Routing

Intro

REpresentational State Transfer

REST is a method of mapping between HTTP routes and CRUD

Create Read Update Delete

RESTful routes is a conventional pattern to follow when structuring different routes for interacting with the server whenever an HTTP request is made by the client.

RESTful Routes

There are 7 restful routes

NamePathHTTP VerbPurposeMongoose Method
Index/dogsGETList all dogsDog.find()
New/dogs/newGETShow new dog formn/a
Create/dogsPOSTCreate a new dog, then redirect somewhereDog.create()
Show/dogs/:idGETShow info about one specific dogDog.findById()
Edit/dogs/:id/editGETShow edit form for one dogDog.findById()
Update/dogs/:idPUTUpdate particular dog, then redirect somewhereDog.findByIdAndUpdate()
Destroy/dogs/:idDELETEDelete a particular dog, then redirect somewhereDog.findByIdAndRemove()

Why do we use RESTful Routes?

REST is merely a convention. It is not at all technically necessary when creating your application routes. However like many conventions, it is useful because it makes your application predictable, which is useful for any other developers who may be working on it in the future. Much like semantic variables.

Nested Routes

In many cases our routes will need to be nested. For example if we need comments to be associated with a specific blog post, we need to specify the ID of the blog post in the route.

NEW blogs/:id/comments/new GET

CREATE blogs/:id/comments POST

Comments

Recent Work

Free desktop AI Chat client, designed for developers and businesses. Unlocks advanced model settings only available in the API. Includes quality of life features like custom syntax highlighting.

Learn More

BidBear

bidbear.io

Bidbear is a report automation tool. It downloads Amazon Seller and Advertising reports, daily, to a private database. It then merges and formats the data into beautiful, on demand, exportable performance reports.

Learn More