Skip to main content

Makes RESTful CRUD easier

Project description

Makes RESTful CRUD easier.

Quick start for contributing

virtualenv -p `which python3.4` virtualenv
source virtualenv/bin/activate
pip install -r requirements.txt
pip install -r dev_requirements.txt
nosetests

Usage

Declare your SQLAlchemy models:

from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import create_engine, Column, Integer, String

Base = declarative_base()

class Employee(Base):
    __tablename__ = 'employees'
    id      = Column(Integer, primary_key=True)
    name    = Column(String(50))

Declare your resources:

from falcon_autocrud.resource import CollectionResource, SingleResource

class EmployeeCollectionResource(CollectionResource):
    model = Employee

class EmployeeResource(SingleResource):
    model = Employee

Apply them to your app, ensuring you pass an SQLAlchemy session to the resource classes:

from sqlalchemy.orm.session import sessionmaker
from sqlalchemy import create_engine
import falcon
import falconjsonio.middleware

Session     = sessionmaker()
db_engine   = create_engine('sqlite:///stuff.db')
db_session  = Session(bind=db_engine)

app = falcon.API(
    middleware=[
        falconjsonio.middleware.RequireJSON(),
        falconjsonio.middleware.JSONTranslator(),
    ],
)

app.add_route('/employees', EmployeeCollectionResource(db_session))
app.add_route('/employees/{id}', EmployeeResource(db_session))

This automatically creates RESTful endpoints for your resources:

http GET http://localhost/employees
echo '{"name": "Jim"}' | http POST http://localhost/employees
http GET http://localhost/employees/100
echo '{"name": "Jim"}' | http PUT http://localhost/employees/100
echo '{"name": "Jim"}' | http PATCH http://localhost/employees/100
http DELETE http://localhost/employees/100

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

falcon-autocrud-0.0.5.tar.gz (5.4 kB view details)

Uploaded Source

File details

Details for the file falcon-autocrud-0.0.5.tar.gz.

File metadata

File hashes

Hashes for falcon-autocrud-0.0.5.tar.gz
Algorithm Hash digest
SHA256 561922a10b8f4a49981f51ccf8d49de96820df2f64f9c9b932963d8508b7e284
MD5 89a973073550c2eddd9c6d2aa8f5d2cc
BLAKE2b-256 fa52bdd8af64f4791b9209a6bc10d93775a15b54a875848ba8ec7dd5412ab4be

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page