-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblog.py
47 lines (35 loc) · 1.03 KB
/
blog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from bson import json_util
from bson.objectid import ObjectId
from flask import Flask, request
from flask_pymongo import PyMongo
from flask_cors import CORS
import pymongo
app = Flask(__name__)
CORS(app, supports_credentials=True)
mongo = PyMongo(app)
with app.app_context() as c:
# DB setup / cleanup
pass
def safe_object_id(code):
try:
return ObjectId(code)
except:
return None
# Example usage: check_fields(json_body, ['email', 'first_name', 'last_name'])
def check_fields(required_fields, given_fields):
return set(required_fields) == set(given_fields)
@app.route('/authors', methods=['GET', 'POST'])
def authors():
return '', 405
@app.route('/authors/<author_id>', methods=['GET', 'PATCH', 'DELETE'])
def author(author_id):
return '', 405
@app.route('/posts', methods=['GET', 'POST'])
def posts():
return '', 405
@app.route('/posts/<post_id>', methods=['GET', 'PATCH', 'DELETE'])
def post(post_id):
return '', 405
@app.route('/login', methods=['POST'])
def login():
return '', 405