The following application is just an example on running a Falcon API with MongoDB in Docker containers. This application does not have any security or authentication (yet). Use it at your own risk.
This application creates and runs 3 docker containers:
- Falcon API running on port 9009. Gunicorn serves as web server.
- Mongo database running in default port 27017
- Mongo Express web based mongo client running on port 8081
To run the API just run
docker-compose up --build
Once the Gunicorn is up and running, you can test that everything is ok going to
http://localhost:9009/ping
In postman folder you can get a Postman collection with examples to test the API
To get a list of all existing players, do a GET request to
http://localhost:9009/players
Pay attention to the lack of trailing slash
To get a player, do a GET request to
http://localhost:9009/players/{_id}
To create a new Player do a POST request to
http://localhost:9009/players
Example JSON body
{
"username": "BestPlayer",
"email": "[email protected]",
"first_name": "John",
"last_name": "Doe",
"phone": "+0118796353",
"date_of_birth": "1984-02-29 10:10:10",
"gender": "M"
}
To create a new Player do a PATCH request to
http://localhost:9009/players/{_id}
Example JSON
{
"first_name": "Jane",
"last_name": "Doe",
"phone": "+0118436353",
"date_of_birth": "1953-02-19 10:10:10",
"gender": "F"
}
To delete an existing player, do a DELETE request to
http://localhost:9009/players/{_id}
If you run this in a Windows environment and you get this error:
standard_init_linux.go:211: exec user process caused "no such file or directory"
you may need to set up your git to run the follwing script in order to avoid git to rewrite the End of Lines in the files.
git config core.eol lf
git config core.autocrlf input
Or you can set it up globally
git config --global core.eol lf
git config --global core.autocrlf input
ERROR: for backend Cannot create container for service backend: status code not OK but 500: {"Message":"Unhandled exception: Drive has not been shared"}
If you are in Windows, you need to enable file sharing between your host and the container by going right click in Docker's icon in system tray and Settings > Resources > File Sharing