The HTTP server base project is meant to be used as a starting ground for creating a JSON API server.
You can run the HTTP server by running the following command from the root of the project.
The default port will be listening on 8000.
Command
go run cmd/server/main.go
Initial Log Output
2024/03/24 00:41:52 HTTP server starting
2024/03/24 00:41:52 HTTP server listening on port 8000
Request (basic)
curl http://localhost:8000/api/v1/ping
Response
{
"data": "pong"
}
Request (with metadata)
curl http://localhost:8000/api/v1/metadata
Response
{
"data": [
"meta",
"data"
],
"metadata": {
"limit": 10,
"offset": 0,
"total": 2
}
}
Request
curl http://localhost:8000/api/v1/notfound
Response
{
"error": {
"message": "The path you requested was not found.",
"status": 404,
"type": "PATH_NOT_FOUND"
}
}
Request
curl http://localhost:8000/api/v1/auth
Response
{
"error": {
"message": "Your request is missing an authorization token.",
"status": 401,
"type": "AUTH_TOKEN_MISSING"
}
}
Request
curl http://localhost:8000/api/v1/auth --header 'Authorization: Bearer invalid'
Response
{
"error": {
"message": "Your request has an invalid authorization token.",
"status": 401,
"type": "AUTH_TOKEN_INVALID"
}
}
Request
curl http://localhost:8000/api/v1/auth --header 'Authorization: Bearer valid'
Response
{
"data": "authenticated"
}