Thanks for asking this question. URL based routing is a feature of a web server. Therefore the specifics of implementation are dependant upon the rules enforced by the web server. Nginx, express, sinatra all have their own “style” of routing. But the general principle of execution of a request are the same across different servers.
Consider for example that your web server is running on the endopint
Let us say that you access a location /foo
The URL parsing engine will
-
Extract the relative path from the url. In our example /foo
-
It will invoke the processing code that is associated with /foo. This is the web server specific part. In your web server there would be a function that would execute everytime /foo is accessed.
-
The web server will now execute the corresponding function and then return the result to the client. When and how the result is returned depends upon the concurrency model of the webserver, which is explained below.
Parameters can also be passed to the url like so
http:/localhost/foo?a=1&b=2
In this case these parameters will be passed along to the function that is responsible for processing the /foo path. These parameters can be utilized to pass some sort of state information (like in case of paging) or some other information that can be used by the function to give an appropriate result to the user.
Web servers also allow the routes to become Method specific. For example a certain route might only execute when client sends a GET request. Yet other routes may only execute POST request. This lets you “overload” URLs allowing you to send a response depending upon the method of the request even when the name is the same. For example
/foo when invoked with a GET method may give a different result than /foo when invoked with a POST.
The concurrency model
The web server is responsible for handling not only the url specific request but also maintaining what is known as concurrency. Since a web server can be accessed by multiple clients at once you don’t want any particular request to block the execution of the entire web server. The kind of concurrency model used is again web server specific. Some web servers dedicate one thread per request. Other web servers use an event driven model. Many use a mix between the two.
Workrock Engineering
WRE
workrocin@gmail.com









