Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/akmamun/mvc-flask-pymongo
Model-Based Python and Mongo DB Web Restful Service
https://github.com/akmamun/mvc-flask-pymongo
api-validator flask flask-model flask-mongodb flask-mongoengine flask-validator microservice mongodb mvc-pattern python python-mongodb python-validator validation
Last synced: 3 months ago
JSON representation
Model-Based Python and Mongo DB Web Restful Service
- Host: GitHub
- URL: https://github.com/akmamun/mvc-flask-pymongo
- Owner: akmamun
- License: mit
- Created: 2019-04-09T18:11:08.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-04-16T10:56:39.000Z (almost 6 years ago)
- Last Synced: 2024-10-02T09:13:38.548Z (4 months ago)
- Topics: api-validator, flask, flask-model, flask-mongodb, flask-mongoengine, flask-validator, microservice, mongodb, mvc-pattern, python, python-mongodb, python-validator, validation
- Language: Python
- Homepage:
- Size: 26.4 KB
- Stars: 24
- Watchers: 2
- Forks: 20
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
## Model Based Validator design for Flask (Python) and Mongo DB
#### Model based custom validation for flask (python). Use Flask server and mongo db. Integrate with any SPA 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/todos`| Get All|
| `GET` | `http://127.0.0.1:5000/todos/todo_id`| Get Single Id|
| `POST` | `http://127.0.0.1:5000/todos`| Insert One|
| `PUT` | `http://127.0.0.1:5000/todos/todo_id`| Update One|
| `DELETE` | `http://127.0.0.1:5000/todos/todo_id`| Delete One|- To see route list type cli `flask routes`
### Lets run the App
```sh
python app.py
```