RESTful Routing
Intro
REpresentational State Transfer
REST is a method of mapping between HTTP routes and CRUD
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
Name | Path | HTTP Verb | Purpose | Mongoose Method |
---|---|---|---|---|
Index | /dogs | GET | List all dogs | Dog.find() |
New | /dogs/new | GET | Show new dog form | n/a |
Create | /dogs | POST | Create a new dog, then redirect somewhere | Dog.create() |
Show | /dogs/:id | GET | Show info about one specific dog | Dog.findById() |
Edit | /dogs/:id/edit | GET | Show edit form for one dog | Dog.findById() |
Update | /dogs/:id | PUT | Update particular dog, then redirect somewhere | Dog.findByIdAndUpdate() |
Destroy | /dogs/:id | DELETE | Delete a particular dog, then redirect somewhere | Dog.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
Basalt
basalt.softwareFree 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.
BidBear
bidbear.ioBidbear 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.