HTTP Server From Scratch in Go
This project began as a CodeCrafters challenge to implement an HTTP server from scratch in Go. I went through all stages of the challenge, learning along the way and always diving deeper to have a better understanding of the protocol. I even read and consulted parts of the RFC when in doubt, possibly the first time I actually read an RFC.
Beyond the CodeCrafters challenge I went deeper and added more features to turn it into a full-fledged learning project.
I used net.Listen()
from the stdlib
for TCP connection handling and built my server around that, having then to implement on my own:
- HTTP request parsing
- Handling of HTTP methods (GET, POST, etc.)
- Request routing
- Support for wildcards
- Support for query params
- Header and status code handling
- HTTP response generation
- Support for persistent connections (Keep-Alive)
I had been doing backend development on my own for a while, but this project taught me a lot of the basics and core principles I overlooked when I created my first API.
Not only did it teach me a lot about these fundamentals,
it also expanded my knowledge of some important components from the net/http
package that are used regularly when building APIs.
There is still a lot I missed and did not implement, but at least now I have a better overview of the stuff I don’t know, instead of just being oblivious.