Beispiel #1
0
from flask.ext.restful import Resource
from flask_api_template import app
from flask_api_template.factory.api import api

class IndexAPI(Resource):
    def __init__(self):
        super(IndexAPI, self).__init__()

    def get(self):
        return {'content': 'foobar'}

api.add_resource(IndexAPI, app.config['API_VERSION'] + '/index')
Beispiel #2
0
        return {'entries': entryList}

    def post(self):
        p = reqparse.RequestParser()
        p.add_argument('value', type = str, required = True, help = 'No value provided', location = 'json')

        args = p.parse_args()

        entry = Entry(value=args['value'])
        db.session.add(entry)
        db.session.commit()

        return {'entry': entry.marshal()},201

api.add_resource(EntryListAPI, app.config['API_VERSION'] + '/entries')

class EntryAPI(Resource):
    def __init__(self):
        super(EntryAPI, self).__init__()

    def get(self, id):
        entry = Entry.query.filter_by(id=id).first()

        if entry == None:
            abort(404)

        return {'entry': entry.marshal()}

    def put(self, id):
        p = reqparse.RequestParser()