https://github.com/akmamun/flask-pymongo
Python (Flask) and Mongo DB Restful Micro Service Architecture
https://github.com/akmamun/flask-pymongo
api-validator custom-validation field-validation flask flask-validator form-validation model mongo-db mongoengine python python-validator rest-api restful-flask restful-webservices validator
Last synced: 8 days ago
JSON representation
Python (Flask) and Mongo DB Restful Micro Service Architecture
- Host: GitHub
- URL: https://github.com/akmamun/flask-pymongo
- Owner: akmamun
- License: mit
- Archived: true
- Created: 2019-01-28T19:15:47.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-08-06T07:42:58.000Z (about 6 years ago)
- Last Synced: 2025-01-19T19:39:23.112Z (9 months ago)
- Topics: api-validator, custom-validation, field-validation, flask, flask-validator, form-validation, model, mongo-db, mongoengine, python, python-validator, rest-api, restful-flask, restful-webservices, validator
- Language: Python
- Homepage:
- Size: 37.1 KB
- Stars: 2
- Watchers: 3
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
## Model Based Restful Flask and Mongo DB
![]()
### Note: Front-end React API Integration Here [react-api-integration](https://github.com/mrxmamun/react-api-integration.git)
- Without restful package try this one [flask-mvc-pymongo](https://github.com/mrxmamun/flask-mvc-pymongo.git)
#### Model based restful flask (python) and mongo db. Integrate with any API development.### Create [virtual environment]('https://docs.python.org/3/library/venv.html) and install requirements
```sh
pip install -r requirements.txt
```
### Configure Database
#### From [db_config.json](src/db_config.json) configure datbase url, name, user and password
```json
{
"db": {
"url" : "mongodb://localhost:27017/",
"name" :"db_name",
"user" :"",
"password" :""
}
}
```## In model update collection name and desire fields name and fields type. For example see todo [model](src/models/todo.py) file
#### From [model](src/models) folder write your individual model and configure db collection name, fields name and fields type
#### Example
##### In todo [model](src/models/todo.py) update collection name, fields name and fields type
```py
collection_name = 'todos' # collection name
fields = {
"title" : "string",
"body" : "string",
"created" : "datatime"
}
```##### Update required fields, optional fields from todo [model](src/models/todo.py)
```py
create_required_fields = [] # example create_required_fields = ["title", "body"]
create_optional_fields = [] # example create_required_fields = ["created"]
update_required_fields = []
update_optional_fields = []
```
#### Example
```py
create_required_fields = ["title", "body"]
create_optional_fields = []
update_required_fields = ["title", "body"]
update_optional_fields = []
```
#### In [Database](src/factory/database.py) insert, find , find_by_id, update and delete methods are generalize methods.
#### Those methods are call from [model](src/models)
- `insert` method store data to database after confirm validation from model
- `find` method retries all data from mongo database
- `find_by_id` method retries back a single search data
- `update` method store updated data to database with corresponding id
- and `delete` method delete data from database with corresponding id#### List of Todo Routes
| Request | Endpoint | Details |
| --- | --- | --- |
| `GET` | `http://127.0.0.1:5000/api/v1/todos`| Get All|
| `GET` | `http://127.0.0.1:5000/api/v1/todos/todo_id`| Get Single Id|
| `POST` | `http://127.0.0.1:5000/api/v1/todos`| Insert One|
| `PUT` | `http://127.0.0.1:5000/api/v1/todos/todo_id`| Update One|
| `DELETE` | `http://127.0.0.1:5000/api/v1/todos/todo_id`| Delete One|- To see route list type cli `flask routes`
### Lets run the App
```sh
python app.py
```