gttp is a simple, lightweight, and performance-focused HTTP server built from scratch in Go.
It provides a minimal API for registering routes and starting an HTTP server, while keeping the internals clear and easy to understand.
The goal of gttp is to make HTTP server development simple while exploring how routing, request handling, response writing, and TCP-level server behavior work under the hood.
Instead of exposing a large framework API, gttp keeps things minimal:
gttp.Handle(method, path, handler)
gttp.Listen(port)- Simple route registration
- Method-based handlers
- Minimal public API
- Custom HTTP response writer
- Buffered response writing
- Basic dynamic route parameter support
- TCP connection handling
- Keep-alive connection support
- Lightweight internal routing
- Built from scratch in Go
go get github.com/Ryankhlifi/gttppackage main
import (
"net/http"
"github.com/Ryankhlifi/gttp"
)
func main() {
gttp.Handle(http.MethodGet, "/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello from gttp"))
})
gttp.Handle(http.MethodGet, "/users/{id}", func(w http.ResponseWriter, r *http.Request) {
id := r.PathValue("id")
w.Write([]byte("User ID: " + id))
})
gttp.Listen("8080")
}Then run the server:
go run main.goVisit:
http://localhost:8080Registers a route with an HTTP method, path, and handler function.
gttp.Handle(http.MethodGet, "/hello", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello world"))
})Starts the HTTP server on the given port.
gttp.Listen("8080")gttp supports simple dynamic route parameters.
gttp.Handle(http.MethodGet, "/users/{id}", func(w http.ResponseWriter, r *http.Request) {
id := r.PathValue("id")
w.Write([]byte("User ID: " + id))
})Example request:
GET /users/42Response:
User ID: 42Performance is one of the main goals of gttp.
A basic load test was performed using bombardier against a simple GET /users route.
Benchmark command:
PS C:\Users\Lenovo\GolandProjects\awesomeProject> & "$env:USERPROFILE\go\bin\bombardier.exe" -c 100 -n 1000000 http://localhost:8080/usersBenchmark result:
Bombarding http://localhost:8080/users with 1000000 request(s) using 100 connection(s)
1000000 / 1000000 [==========================================================================================================================================] 100.00% 226201/s 4s
Done!
Statistics Avg Stdev Max
Reqs/sec 232295.32 20709.41 278288.30
Latency 429.09us 189.98us 26.70ms
HTTP codes:
1xx - 0
2xx - 1000000
3xx - 0
4xx - 0
5xx - 0
others - 0
Throughput: 44.28MB/sSummary:
- Total requests:
1,000,000 - Concurrent connections:
100 - Average requests/sec:
232,295.32 - Average latency:
429.09µs - Successful responses:
1,000,000 - Throughput:
44.28MB/s
These results may vary depending on hardware, operating system, Go version, and benchmark route behavior.
gttp focuses on:
- keeping the developer API simple
- reducing unnecessary framework complexity
- improving request handling performance
- understanding HTTP server internals
- experimenting with routing and connection handling in Go
This project is licensed under the Apache-2.0 License.