REST_Url_Conventions..
What is REST & Naming Guide
Hi everyone Welcome again for a another Techie Talk…
Today im going to talking about the REST and its Naming Structure. Lets go to the rest.
What is REST?
First let’s know the abbreviation of the rest REpresentational State Transfer. and an architectural style for distributed hypermedia systems. REST has its guiding principles and constraints, if a service interface needs to be referred to as Restful it must be fulfill these principles.
REST Principles
- Uniform interface
- Client–server
- Stateless
- Cacheable
- Layered system
- Code on demand (optional)
So now let’s see how to design the rest full URLs.
Represent Hierarchical relationships by “/”
If we have a hierarchical type relation like,
Product_category > Subcategory > product.
in this case we have one product_category and it has multiple subcategories and that sub category have multiple products so if we found these kind of hierarchical relations its better to use Slash “/” .
Use Plural nouns when required
When you dealing with collections its better to represent it on your URL. As an example Organization has too many departments. so that we use “departments” rather than “department” to Indicate the plural.
Design to improve readability
Always ensure that the writing is easy for the reader to read. As an example see this,
The former is quite difficult to read while the latter is relatively easy to read. This one called improving the readability.
Do not use any file extensions like .html .asp .js …. because we are dealing with resources not the web pages.
Use Query parameters for filtering
When we need to filter a query we write it with this format
?Name of the parameter = Value of the parameter
As a example we need employee name saman → ?Employee=saman
Do not used CRUD operations to URLs
Using CRUD operations to rest naming is not a good practice so write url with adding the CRUD operator as a request not in the URL part refer below,