The relationship between the client
end and server
end of an application is facilitated by a principle called REpresentational State Transfer (REST)
.
When a user engages a web application or a website and navigates through its pages, a state transition takes place. This state transition is made possible by (REST)
, which helps to map the REST
principle, we can say it is RESTful
in nature.
Routing on its own is essential in websites and web applications due to the transfer of data from the user end to the server end, as well as a request of data by the user from the client end to the server end. Routing in Node.js is made possible through the express.js
library.
Restful
routing consists of much data
manipulation. Restful
routes are unique, as they can receive HTTP method requests and connect that with a corresponding controller action that has that method and URL. The code is then executed, and the required response to the client is delivered to the client end of the application.
Conventional URLs used on websites make it possible for one to both delete and update personal profiles on web applications. Restful
routes make this particular art of data manipulation very simple. One can make use of the mongoDB
database and express.js
library in a Node.js terminal.
For Restful
routes to be possible, one must ensure:
The use of HTTP and HTTP methods/verbs: These are methods that are HTTP supported, e.g., POST
, GET
, PUT
, etc.
Separate client from server: There should be a clear difference between the client end and the server end.
To not hold state between requests: Clear definition of information. For example, a POST
request should have a corresponding response that would give the desired output.
Reliability: The routing should have no loose ends.
Restful
routes can be used to set up blogs more frequently. The table below is a Restful
route guide for a simple blog.
NAME | PATH | HTTP VERB/METHOD | REASON/PURPOSE |
INDEX | /BLOG | GET | LISTS ALL BLOGS |
NEW | /BLOG/NEW | GET | SHOWS NEW FORM FOR NEW BLOG ENTRY |
CREATE | /BLOG | POST | CREATES A NEW BLOG POST |
SHOW | /BLOG/:ID | GET | SHOWS THE BLOG POST WITH THE GIVEN ID |
EDIT | /BLOG/:ID/EDIT | GET | EDIT THE BLOG POST WITH THE GIVEN ID |
UPDATE | /BLOG/:ID | PUT | UPDATE THE BLOG POST WITH THE GIVEN ID |
DESTROY | /BLOG/:ID | DELETE | DELETE THE BLOG POST WITH THE GIVEN ID |