Demo - HTTP application
Yokai's showroom provides an HTTP demo application.
Overview
This HTTP demo application is a simple REST API (CRUD) to manage gophers.
It provides:
- a Yokai application container, with the HTTP server and SQL modules to offer the gophers API
- a MySQL container to store the gophers
- a Jaeger container to collect the application traces
Layout
This demo application is following the recommended project layout:
cmd/
: entry pointsconfigs/
: configuration filesdb/
:migrations/
: database migrationsseeds/
: database seeds
internal/
:handler/
: HTTP handlersmiddleware/
: HTTP middlewaresmodel/
: modelsrepository/
: models repositoriesservice/
: servicesbootstrap.go
: bootstrapregister.go
: dependencies registrationrouter.go
: routing registration
templates/
: HTML templates
Makefile
This demo application provides a Makefile
:
make up # start the docker compose stack
make down # stop the docker compose stack
make logs # stream the docker compose stack logs
make fresh # refresh the docker compose stack
make migrate # run database migrations
make test # run tests
make lint # run linter
Usage
Start the application
To start the application, simply run:
After a short moment, the application will offer:
- http://localhost:8080: application dashboard
- http://localhost:8081: application core dashboard
- http://localhost:16686: jaeger UI
Available endpoints
On http://localhost:8080, you can use:
Route | Description | Type |
---|---|---|
[GET] / |
Dashboard | template |
[GET] /gophers |
List all gophers | REST |
[POST] /gophers |
Create a gopher | REST |
[GET] /gophers/:id |
Get a gopher | REST |
[DELETE] /gophers/:id |
Delete a gopher | REST |
Authentication
This demo application provides an example authentication middleware.
You can enable authentication in the application configuration file with config.authentication.enabled=true
.
If enabled, you need to provide the secret configured in config.authentication.secret
as request Authorization
header.