Skip to content

jstacoder/sa-flask-restful-resource

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

##SA-FLASK-RESTFUL-RESOURCE

###Finally creating Api resources from sqlalchemy models is easy again!!!

to use:

$ pip install sa-flask-restful-resource

then just define:

  • your models
  • your app
  • and create / register the resource
    • pass your model to your Api when you register it
    • pass it as a keyword arg called resource_class_kwargs
from sqlalchemy.ext.declarative import declarative_base
from flask import Flask
from flask_restful import Api
from sa_flask_restful_resource import BaseResource

base = declarative_base()

class MyModel(base):
    pass

app = Flask(__name__)
api = Api(app)

class ModelResource(BaseResource):
    pass

api.add_resource(ModelResource,'/myresource',resource_class_kwargs=dict(model=MyModel))

app.run()

now you have these routes defined:

'/myresource' -> GET(get all resources),POST(create a new resource)
'/myresource/<int:item_id>' -> GET(get resource identifed by item_id)

this is a work in progress, pull requests are welcome, i plan on adding more automatic routes in the future.

for more detailed usage, see the demo and test files.

About

base Resource class, for creating api's with sqlalchemy and flask

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages