Simple REST-API Boilerplate
This is a simple implementation of REST-API using Golang and several packages (Echo and GORM). By default, I use PostgreSQL database from Docker Images. There are two ways to run this app, using Docker or run manually on your system. I suggest to use Docker if possible.
1. Docker
- Go to directory folder and type:
docker-compose up -d
Note: The process will running into the background because we add option
-d (detach mode)
- The server can be accessed through port
8080
2. Local
Prerequisites: Make sure you've already installed Golang and PostgreSQL on your system.
- Create a table on PostgreSQL by copying the SQL syntax inside file
docker_pg_init.sql
- Go to directory folder and insert the environment variables below on terminal (bash/zsh):
export DB_HOST=localhost
export DB_PORT=5432
export DB_USER=postgres
export DB_PASSWORD=postgres
export DB_DATABASE=db_exercise
export SERVER_PORT=8080
Note: You can customize the value by desire.
- Type below to execute the app:
go run main.go
- Server can be accessed through port
8080
Available Endpoints:
/api/students (GET)
/api/students (POST)
Request body:
{"name": "user1"}