Summary
In this chapter, we covered the basics of the :gen_tcp
module. We saw how :gen_tcp
allows us to create a connection using a TCP/IP socket, and how we can use it to write our own HTTP server. We then wrapped the HTTP server into a package while making the implementation for its response configurable using an application environment.
Later, we learned how to test our HTTP server using the Finch HTTP client, and made the server concurrent by spinning up a new process for every HTTP request, similar to what Cowboy does. We also updated our HTTP server to have the ability to run in detached mode just like Phoenix and Cowboy.
Now that we have our own HTTP server up and running, we have to make it easier to define routes and responses. For a complex web application, matching the routes the way we did in Responder
modules wouldn’t be very helpful. Luckily, the Elixir community has a Plug
package that helps us with the entire request-response data manipulation process;...