Home

Awesome

di-example

REST API to manage a list of car stored in mongodb.

It shows how to use sarulabs/di in a web application.

More explanations can be found in this post:

Routes

MethodURLRoleJSON Body example
GET/carsList cars
POST/carsInsert car{"brand": "audi", "color": "black"}
GET/cars/{id}Get car
PUT/cars/{id}Update car{"brand": "audi", "color": "black"}
DELETE/cars/{id}Delete car

Dependencies and vgo

The dependencies are handled with vgo. You need to install vgo first:

go get -u golang.org/x/vgo

Then you can use vgo run main.go to start the application.

Environment

You need to set some environment variables before running this application:

To use the default values you can use the default_env.sh script:

source default_env.sh
vgo run main.go

Run with docker

It is also possible to run this application with docker compose:

docker-compose -f docker/compose.yml up --build

Or if you only want to run mongo in docker and not the rest api:

docker-compose -f docker/mongo.yml up