A simple HTTP server written in Go using a RESTful style API to interact with it.
It doesn't do much, just demonstrates the layout of an Go HTTP server, and might be a good starting point.
- Uses Gorilla web toolkit for routing, and middleware for logging requests.
POST
body is limited usinghttp.MaxBytesReader
, so the server isn't overloaded from malicious requests.- Configurable options for address, port, timeouts, max body size, and performance debugging.
Using docker-compose
:
docker-compose up -d
Alternatively, you can run make build
which places binaries for Linux, macOS, and Windows in the build
directory.
Run the resulting binaries directly with -h
to see command line options!
View data by GET
ing the index route /
:
curl http://localhost:8000
Create some data by POST
ing to the resource
route:
curl http://localhost:8000/resource -d '{"Name":"Bob"}' -H "Content-Type: application/json"
View data by GET
ing the resource/{id}
route:
curl http://localhost:8000/resource/1
There's a lot more to be added to make this a real application! Here's a few examples:
- Access data from a database, or some other pluggable source (e.g. for testing)
- Check for data, output HTTP status not found if missing
- Add support for DELETE requests
- Authentication
- Versioned API, e.g. https://mysite.com/v1/resource/1
- Use some kind of standard specification, e.g. OpenAPI or JSON API
- Validate POST data matches expectations, e.g. correct fields provided
- Tests