JeroenDeDauw/pamela — Issue #1: Python != php
Author: ab3
Created: 2011-11-14 19:10:34+00:00
State: open

1) There is no need for implementing custom routing to express which function has to handle which request,
you can easily do this with @app.route(). Delete all this apiBase, api*Entry, Params, apiException, ...
2) You should do 'parameter checking' in the model and not in the 'view/controller'. Do a 'try/catch' or even an '... or abort(404)' in you handler to see if a request is valid.
3) If you are creating an api use the http methods to make it RESTful.
4) Use an existing documentation lib like [sphinx](http://sphinx.pocoo.org/), don't write your own.
5) Your code easily fits in 2 files, models.py for you model, and api.py for your request handlers, for the love of God, don't put code in \__init\__.py
6) What is this enum stuff you are doing and why?
7) Read some more about the sqlalchemy object mapping, no need for this toDict and fromDict stuff.
8) I wrote you a litle mock app just to give you and idea

from flask import Flask, request, jsonify
from flaskext.sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
db = SQLAlchemy(app)

@app.route('/api')
def list_entries():
entries = Entry.query.all()
return jsonify({'entries': entries})

@app.route('/api', methods='POST')
def create_entry():
entry = Entry(name=request.args['name'])
db.session.add(entry) or abort(409)
return '201, Created'

@app.route('/api/' methods='PUT')
def edit_entry(entry_id):
entry = Entry.filter_by(id=entry_id).first() or abort(404)
entry.name = request.args['name']
db.session.add(entry)
return '200, Ok'

@app.route('/api/', method='DELETE')
def delete_entry(entry_id):
entry = Entry.filter_by(id=entry_id).first() or abort(404)
db.session.delete(entry)
return '200, Ok'