Configuring an HTTP server to perform echoing and routing
We learned how to serve the same response forever, but that would get pretty dull after a while. In this recipe, you are going to learn how to read requests and respond to them individually. For this, we will use routing to differentiate between requests to different endpoints.
Getting ready
To test this recipe, you will need a way to easily send HTTP requests. An excellent free tool for this is Postman (https://www.getpostman.com/), which features a nice and self-explanatory UI. If you'd rather not download anything, you can use your terminal for this. If you're on Windows, you can open PowerShell and enter the following to do an HTTP request:
Invoke-WebRequest -UseBasicParsing <Your URL> -Method <Your method in CAPSLOCK> -Body <Your message as a string>
So, if you wanted to POST the message hello there, my echoing friend
to http://localhost:3000/echo
, as you will be asked to later in the recipe, you'd need to enter...