Template-based Routing
When working with web APIs, you would have come across many varieties of URIs such as /product/12
, /product/12/orders
, /departments/
, /books
, and so on.
In the web API world, they are known as Route--a string describing a URI template. For example, a sample route can be formed on this URI pattern: /products/{id}/orders
.
There are few points to observe here:
- A URI template consists of literals and parameters
- Products and orders are literals in the preceding sample example
- Anything in curly braces { } is known as parameters--
{id}
is one such example - A path separator (
/
) has to be a part of a route template--The URIs understand/
as path separators - The combination of literals, path separator, and parameters should match the URI pattern
When working with a web API, literals will either be controllers or methods. The route parameters play a significant role in making a route template multipurpose. Parameters in curly braces can play multipurpose roles as follows:
- Even though route...