Makes RESTful CRUD easier
Project description
# Falcon-AutoCRUD
Makes RESTful CRUD easier.
## Test status
[ ](https://codeship.com/projects/134046)
## Quick start for contributing
virtualenv -p `which python3` 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))
age = Column(Integer)
```
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
http GET http://localhost/employees?name=Bob
http GET http://localhost/employees?age__gt=24
http GET http://localhost/employees?age__gte=25
http GET http://localhost/employees?age__lt=25
http GET http://localhost/employees?age__lte=24
http GET http://localhost/employees?name__contains=John
http GET http://localhost/employees?name__startswith=John
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
```
Makes RESTful CRUD easier.
## Test status
[ ](https://codeship.com/projects/134046)
## Quick start for contributing
virtualenv -p `which python3` 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))
age = Column(Integer)
```
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
http GET http://localhost/employees?name=Bob
http GET http://localhost/employees?age__gt=24
http GET http://localhost/employees?age__gte=25
http GET http://localhost/employees?age__lt=25
http GET http://localhost/employees?age__lte=24
http GET http://localhost/employees?name__contains=John
http GET http://localhost/employees?name__startswith=John
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file falcon-autocrud-0.0.10.tar.gz.
File metadata
- Download URL: falcon-autocrud-0.0.10.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0eddbda4424d76eca4acafcd1ea3ea1a398bedb6449bb0649753381074095a1c
|
|
| MD5 |
2001def4b506d9dc8b48258bd22a3dc9
|
|
| BLAKE2b-256 |
a6e28ba0784be6a2b485d0caa2693f884b851c57f3b0be3df774b221a38ab2c2
|