A learning project to build an HTTP server from scratch on top of TCP sockets in Go. This project explores the inner workings of the HTTP protocol by implementing request parsing, header handling, and response generation at the TCP level.
- Go 1.25.5 or later
Run all tests to verify the implementation:
go test -v ./internal/request/
go test ./...Start the HTTP server on port 42069:
go run ./cmd/httpserver/Press Ctrl+C to gracefully stop the server.
Once the server is running, test it with curl:
POST request with JSON body:
curl -X POST http://localhost:42069/coffee \
-H 'Content-Type: application/json' \
-d '{"type": "dark mode", "size": "medium"}'GET request:
curl http://localhost:42069/use-neovim-btwBoth requests should receive a 200 OK response with the body Hello World!.
cmd/httpserver/- Main server entry pointinternal/request/- HTTP request parsing logicinternal/headers/- HTTP header parsing and handlinginternal/server/- TCP listener and connection handlinginternal/utils/- Utility functions
This project demonstrates:
- TCP socket programming in Go
- HTTP protocol specification (RFC 7230)
- Request line parsing
- Header parsing
- State machine pattern for parsing
- Concurrent connection handling with goroutines
- Graceful server shutdown
This project was inspired by and built following the excellent guidance from the Boot.dev Learn HTTP Protocol with Go course. A huge thank you to the Boot.dev team for making their high-quality learning material available for free.
Note: No AI was used in the coding of this project. I did not purchase a subscription, so I did not have access to the solution files for any of the lessons. All code was written independently based on the course instructions and my understanding of the concepts.
If you're interested in learning how the HTTP protocol works under the hood or want to build projects like this yourself, I highly encourage you to check out the Boot.dev course. It's a fantastic resource for understanding web protocols from first principles.