Do I need to use a framework/Which framework to use to build a REST API in Flask Application

时间:2019-04-08 13:14:43

标签: rest flask flask-restful flask-restplus flask-restless

I have a small Flask application with little traffic using SQLAlchemy.

I have several API routes that use business logic, so at least for now I don't want to have the API on a different server or project.

I just want to move them away from the main bit of my code to make it more readable, so I am wondering whether to use a framework or simply create a Blueprint and have all the API routes there?

I found some info here on the different frameworks:

  • The one that's easiest to implement is Flask-Restless, but looking at the github repository last commit has been 2 years ago.
  • Flask-Restplus
  • Eve Flask-SqlAlchemy version
  • Flask-Restful is said to be outdated in the post?

So I am no expert and don't really know which one to choose if any, or use a Blueprint ( like the one below):

from flask import Blueprint

api = Blueprint('api', __name__)

@api.route("/api/some_classes")
def get_come_classes():
    cs = q.get_some_classes(g.session)
    return JSONResponse(200, {
        "some_classes": [c.render_embeded() for c in cs]
    })

0 个答案:

没有答案
相关问题