Exemplo n.º 1
0
def before_request():
    g.db = get_db()
Exemplo n.º 2
0
# coding: utf-8

""" 
zum Testen:
REST Client (Firefox Addon)

API:
GET http://localhost:5000/messages -> all messages
GET http://localhost:5000/messages/<message_id> -> one message
POST http://localhost:5000/messages "body"

"""

from flask import Flask, jsonify, request, g 
from pseudodb import get_db 
db = get_db()

app = Flask(__name__)

@app.before_request
def before_request():
    g.db = get_db()
    
@app.after_request
def after_request(f):
    g.db.close()
    return f

def fill_db():
    messages =  [{'id':"0", 'type':'default', 'body':"asd"},
                 {'id':"1", 'type':'default', 'body':"qwer"},