The client/server relationship is a prerequisite of a set of principles known as REST(representational state transfer) which provides a way of mapping HTTP verbs ( get, post, put, delete) and CRUD actions (create, read, update, delete) together.
Whenever you navigate through a site by clicking links, you’re making a state transition which brings you to the next page (the next state of application) and by following this simple model of clicking from page to page you’re following the REST principles and when something follows the rest principle it is known as RESTFUL.
So, Restful routes are just a conventional pattern to follow when structuring different routes for interacting with the server whenever an HTTP request is made by the client. And for a route to be completely restful it must do the following:
- Separate the client from the server
- Not hold state between requests (i.e all information necessary to respond to a request is available in each request: no data or state, is held by the server from request to request)
- Use HTTP and HTTP methods
- Be reliable (for e.g most APIs follow the restful route pattern when specifying the process for authentication and important URLs)
There are like 7 different restful routes pattern to follow when creating an application or web service that will interact with the server, for e.g let's look at the 7 routes that can exist in a blog website:
|| NAME | PATH | HTTP VERB | PURPOSE ||
|| Index | /blog | GET | Displays all blog post ||
|| New | /blog/new | GET | Shows new form for new blog entry ||
|| Create | /blog | POST | Creates a new blog post ||
|| Show | /blog/:id | GET | Shows one specified blog post ||
|| Edit | /blog/:id/edit | GET | Shows edit form for one blog post ||
|| Update | /blog/:id | PUT | Updates a particular blog post ||
|| Destroy | /blog/:id | DELETE | Deletes a particular blog post ||
The above table clearly shows the mapping between the HTTP verb and the CRUD actions which follows the above explained restful route patterns. You’d want to have an action to create a new post (new route), to display one post (show route), to display all posts (index route), to delete a post (delete route), and a page to edit a post (edit route).
These different route patterns just display a blueprint for us to follow when creating any restful web services or applications or even when building our APIs. It is a conventional and widely used pattern that you necessarily do not have to follow if you don’t want to.
I hope this has helped explain the basic concept behind restful routing and how the above blog routes table can be implemented in just any application.
As always, Thank you for reading!