Demo web-api written in Go
Effectively the rest example from the official chi project is used and adapted according to need.
Offer a simple API that can be run easily locally. This API can be treated as a "System Under Test" for api testing.
Principle: don't rely on modules that by themselves rely on external depencendies.
The chosen http router is chi. This package provides convenience over having to write the http pipeline boilerplate using the Go std lib. This module is using only the Go std lib, and thus has no external dependencies.
gofakeit is used to seed fixture struct data. This module is using only the Go std lib, and thus has no external dependencies.
Since the introduction of generics in Go 1.18 an experimental x/exp/slices package that offers convenience functions when using slices. This package has been accepted to be included in the official Go std lib
- Build the binary in /cmd/server
- Run the
server
binary in your terminal of choice => this will display: "Server starting on localhost:3000"
Endpoints to investigate:
GET:
- /
- /ping
- /clients
- /clients/{id}
POST:
- /clients {payload}
PUT:
- /clients/{id} {payload}
DELETE:
- /clients/{id}
Payload example
{
"id": string,
"name": string,
"surname": string,
"birthdate": string,
"email": string,
"phone": string,
"age": number
}