Skip to content

mongodb-developer/beanie-example

Repository files navigation

Building a Cocktail API with Beanie!

This is a sample cocktail API built with MongoDB, Beanie, and FastAPI.

This code was written to try out Beanie and was used to write a blog post, which may be more interesting than this code.

Install It

Run the following to install the project (and dev dependencies) into your active virtualenv:

python -m pip install -e .[dev]

Initialize Your Database

The previous step installs a script, init-db, that will generate some random cocktails for you, if you want:

# This will create 100 dummy cocktails in your database
# (or run without --dummy-data to just initialize indexes.):
export MONGODB_URL="mongodb+srv://<user>:<pass>@host/database"
init-db --dummy-data

**Don't consume any of the cocktails this script generates, they're randomly generated!

Run It

If you have an Atlas database you can run the server with:

export MONGODB_URL="mongodb+srv://<user>:<pass>@host/database"
uvicorn beaniecocktails:app --reload

You should then be able to view your API docs at http://127.0.0.1:8000/docs/

Note: This app will only work on MongoDB Atlas clusters, because it makes use of Atlas Search.

Feedback

I'd love to know whether you found this useful, or if you had any problems. Please leave feedback on the MongoDB Community Forums and tag me @Mark_Smith.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published