Table of Contents
This is BananaAPI. A project to demonstrate a possible configuration of a simple API project in Flask. Allows you to work with bananas by CRUD. Uses SQLAlchemy ORM and Marshmallow as a serializer to interact with the database. The project is based on the tutorial by Leonardo Giordani. All API development is done via TDD.
- Install Docker on your machine.
- Clone the repo
git clone https://github.com//Glico21/BananaAPI.git
- Use virtual environments and install all necessary requirements
pip install -r requirements/development.txt
- Also you need to build the container
./manage.py compose build web
The API can work in three modes. In development, production and testing modes.
Development mode runs the application as a separate container, independent of the database, which is also in a separate container. It uses separate development server specific environment variables.
You can run development mode by this command
./manage.py compose up
This command will start the application on localhost 0.0.0.0:5000.
After that, you need to migrate to initialize all the necessary tables for the database.
./manage.py flask db migrate -m "Some message"
And upgrade
./manage.py flask db upgrade
You can check out the available endpoints and see how it all works.
Production mode also runs the application in a separate container, but it can be scalable by nginx and gunicorn.
You can run production server by this command
APPLICATION_CONFIG="production" ./manage.py compose up
If you want scale application for N containers you should use this command
APPLICATION_CONFIG="production" ./manage.py compose up --scale web=N
You can run separate tests for the application. To do this, run the following command.
./manage.py test
A separate database is used for the tests, which is cleared automatically after each test is performed.
URL/Method | GET | POST | PATCH | DELETE |
---|---|---|---|---|
/ |
Return Hello, World! |
|||
/users |
Return count of users in database | |||
/bananas |
Return all banana objects | Create a banana object | ||
/palms |
Return all palms objects | Create a palm object | ||
/bananas/<id> |
Return a specific banana object | Update a banana object | Delete a banana object | |
/palms/<id> |
Return a specific palm object | Update a palm object | Delete a palm object |
In the future it is planned to develop this project a little bit.
- Add a palm tree model, which will be linked to the banana model.
- Add more fields for the banana
- Expand user model
- Add simple authorization and access rights
See the open issues for a full list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Boyko Dmitriy - 21glicodin@gmail.com
Project Link: https://github.com/Glico21/BananaAPI