2. Using restible.ModelResource
¶
Note
You can get the full source code for this example here.
Table of Contents
2.1. Improve the code structure¶
The app in this section will have almost the same level of complexity so we could still implement this section as a single file. We do know the app will grow in the future sections so we might go ahead and structure the project files a bit better so it’s easier to extend them and reference them from the docs where needed.
We will also create a fully fledged pypi package instead of using requirements.txt. On top of requirements, it will also allow us to create define console scripts which we will use to run the devserver.
Project structure:
├─ setup.py
└─ src
└─ restiblog
├─ __init__.py
├─ app.py
├─ models.py
└─ routes.py
And here’s the setup.py we will use for the package.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | # -*- coding: utf-8 -*-
from setuptools import setup, find_packages
setup(
name="restiblog",
version='0.1.0',
author="Mateusz 'novo' Klos",
license="MIT",
url="http://github.com/novopl/restible/tree/docs/examples/02_models",
description="Example app for restible tutorial",
package_dir={'': 'src'},
packages=find_packages('src', exclude=('test', 'test.*')),
install_requires=[
'Flask==1.0.2',
'Flask-SQLAlchemy==2.3.2',
'restible==0.11.11',
'restible-flask==0.2.2',
'serafin==0.12.2',
'serafin-sqlalchemy==0.2',
],
entry_points={
'console_scripts': [
'restiblog = restiblog.app:run_devserver',
]
},
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Programming Language :: Python",
"License :: OSI Approved :: MIT License",
],
)
|
2.2. New base resource class - ModelResource
¶
2.2.1. How RestResource methods map to ModelResource methods¶
RestResource |
ModelResource |
---|---|
rest_query |
query_items |
rest_get |
get_item |
rest_create |
create_item |
rest_update |
update_item |
rest_delete |
delete_item |