This application performs CRUD (Create, Read, Update, Delete) operations on a MongoDB database for a User resource using a REST API. The REST API endpoints are accessible via HTTP requests and can be tested using Postman.
Python 3.8+ Flask PyMongo Docker
- Create a new Python virtual environment and activate it.
- Install the Flask and PyMongo libraries using pip: pip install Flask PyMongo
- Install Postman for testing the REST API endpoints.
- Create a new MongoDB database and collection for the application.
- Open the
app.py
file in your code editor. - Import the necessary libraries: Flask, PyMongo, and jsonify.
- Create a new Flask application instance.
- Set the MongoDB URI and database name in the Flask application configuration.
- Create a new PyMongo client and database instance.
- Create the necessary routes and functions for the REST API endpoints.
- Run the Flask application using the
flask run
command.
- Open Postman and create a new HTTP request for each of the REST API endpoints.
- Send requests to the endpoints to test the CRUD operations on the User resource.
- Verify that the responses are correct and the database is being updated correctly.
- Build the Docker image: docker build -t flask-app .
- Run the Docker image: docker run -p 5000:5000 flask-app
This will run the Docker image and expose port 5000 on the host machine. You can then access the Flask application at http://localhost:5000.
This application was created by Naga Vardhan Chebrolu.