Skip to content

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 points
  • configs/: configuration files
  • db/:
    • migrations/: database migrations
    • seeds/: database seeds
  • internal/:
    • handler/: HTTP handlers
    • middleware/: HTTP middlewares
    • model/: models
    • repository/: models repositories
    • service/: services
    • bootstrap.go: bootstrap
    • register.go: dependencies registration
    • router.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:

make fresh

After a short moment, the application will offer:

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.