Golang basic REST api example
Is a basic example how you can build a simple REST API in Go with go-chi and zap.
Based on https://github.com/golangdk
Used Packages
Environment Variables
In this example we use some different ENV vars:
Name |
HOST |
PORT |
APP_ENV |
Default |
localhost |
8000 |
develop |
Features
- Basic RST-API with go-chi
- Singleton logger
- Request & Response Examples
- validation against post requests
- mask of personal information in response
Prerequisite
How to run
git clone git@github.com:bastian-kurz/go-basic-rest-example.git && cd go-basic-rest-example
HOST=localhost PORT=8081 go run cmd/server/main.go
or
make start
Endpoints
## Get specific user
GET http://localhost:8081/api/user/10
Accept: application/json
###
## Get a list of user
GET http://localhost:8081/api/user
Accept: application/json
###
## Valid Request
POST http://localhost:8081/api/user
Content-Type: application/json
{
"userName": "doe",
"email": "john.doe@testsubject.de",
"firstName": "John",
"lastName": "Doe",
"password":"foobar"
}
###
## Invalid Request
POST http://localhost:8081/api/user
Content-Type: application/json
{
"userName": "!!",
"email": "john.doe@@@testsubject.de",
"firstName": "John",
"lastName": "Doe13",
"password":"foobar"
}
###