
Puppy API rip off (exercise)
Simple api that serves recipes for puppies. This project is a step by step guide on how to create a simple api using
Go programming language. The purpose of the project is to demonstrate to new comers the language basic features and
concepts.
The exercise is based on recipepuppy free api. All the puppy recipes used were also
retrieved from there.
Project is divided into nine steps, each step has its own branch.
- 00-CI
- 01-Server
- 02-Configuration
- 03-Logging
- 04-Handlers
- 05-Routes
- 06-Database
- 07-Handler-real-data
- 08-Middleware
- 09-Authentication
- 10-Swagger
Prerequisites
Starting database container
docker-compose up -d
Setup databases
Set up required databases. At each execution recreates database and re imports data.
make db
Set up/reset only dev-db
make db-dev
Set up/reset only test-db
make db-test
Configuration
Most of the project values can be configured by editing config.yaml, config file is located under the project
root folder.
- JSON
- TOML
- YAML
- HCL
- envfile
You can override any config value by using environmental values, for example to override token.ttl you need to set an
environmental variable with key RECIPE_TOKEN_TTL
Project is using Viper config a complete configuration solution for Go
applications
Running tests
make test
Running project
make run
Building project
make build
Running linter
make lint
if you are behind a corporate firewall using a custom certificate use
make lint-insecure
Project is using golang lint linter
Usage examples
Get recipe
http://127.0.0.1:8080/api/recipe/1 [GET]
Get Recipes
http://127.0.0.1:8080/api/recipes?ingredient=onions&ingredient=garlic&term=omelet&page=1 [GET]
User Sign up
http://127.0.0.1:8080/api/user/signup [POST]
{
"email":"email@email.com",
"username":"username2",
"password":"password",
"repeatPassword":"password",
"fullName":"test user"
}
User Sign in
http://127.0.0.1:8080/api/user/signin [POST][body]
{
"username": "username1",
"password": "password"
}
User Profile
http://127.0.0.1:8080/api/user [GET]
Postman
For your convenience Postman collection/environment files are available at
api/Recipes.postman_collection.json
api/Recipes.postman_environment.json
Available Parameters explanation:
- ingredient : list of ingredients
- term : text search in titles
- page : page number
Swagger Docs
You can view swagger docs after running the app here http://127.0.0.1:8080/swagger/index.html
Project is using swaggo/swag to generate/update swagger docs you can install
the cli using the following command
go get github.com/swaggo/swag/cmd/swag
Update swagger docs
swag init --dir cmd/api --output api/swagger
or
make swagger
Authors
- George Lavdanis - Initial work - georlav
License
This project is licensed under the MIT License - see the LICENSE file for details