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:
Method | URL | Role | JSON Body example |
---|---|---|---|
GET | /cars | List cars | |
POST | /cars | Insert car | {"brand": "audi", "color": "black"} |
GET | /cars/{id} | Get car | |
PUT | /cars/{id} | Update car | {"brand": "audi", "color": "black"} |
DELETE | /cars/{id} | Delete car |
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.
You need to set some environment variables before running this application:
8080
)127.0.0.1:27017
)To use the default values you can use the default_env.sh
script:
source default_env.sh
vgo run main.go
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