This is a small project to learn developing rest api in GoLang inspired by article series by Stephen Walther. Goal of the project is to develop a simple rest api that would serve a /health
endpoint and CRUD endpoints for a single resource Movie
. There would be no authentication/authorisation.
This would also demonstrate how to run sql migration scripts using dbmate. This can be replaced with any other database migration tool that you want to learn and evaluate e.g. I have used RoundhousE in the past.
Development dependencies can be started with docker-compose
. This would start up PostgreSQL server and create and run docker image to run database migration on PostgreSQL server.
docker-compose -f docker-compose.dev-env.yml up -d
This is only needed if you are going to run api against PostgreSQL. There is an in memory store available in code, that can be used instead of PostgreSQL.
Use following command to start application from command line
DATABASE_URL=postgres://postgres:Password123@127.0.0.1:5432/moviedb?sslmode=disable go run cmd/api/main.go
- GET
/health
- GET
/movies
list all movies - GET
/movies/{id}
get movie by id - POST
/movies
create a new movie - DELETE
/movies/{id}
delete a movie
This not a most acurate representation of how you would model a movie resource in an acutal system, just a mix of few basic types and how to handle those in rest api.
Field | Type |
---|---|
ID | UUID |
Title | String |
Director | String |
Director | String |
ReleaseDate | Time |
TicketPrice | float64 |
There is an Insomnia Document in the repository that can be used to test the api with Insomnia Rest Client.