Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: create REST API #357

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ django-extensions==1.7.9
django-model-utils==3.0.0
#tastypie 0.13.3 has breaking changes
django-tastypie==0.13.1
formencode==1.3.1
futures==3.0.5 # used by gunicorn's async workers
gevent==1.2.1 # used by gunicorn's async workers
gunicorn==19.7.1
inflect==0.2.1
jsonfield==2.0.1
logutils==0.3.4.1
lxml==3.7.3
Expand Down
1 change: 1 addition & 0 deletions requirements/test.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Test dependencies go here.
-r base.txt

django_mock_queries==2.0.0
pytest
pytest-cov==2.4.0
coverage==4.2
Expand Down
2 changes: 2 additions & 0 deletions storage_service/locations/api/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.conf.urls import include, url
from tastypie.api import Api
from locations.api import v1, v2
import locations.api.v3 as v3_api

from locations.api.sword import views

Expand All @@ -19,6 +20,7 @@
v2_api.register(v2.AsyncResource())

urlpatterns = [
url(r'v3/', include(v3_api.urls)),
url(r'', include(v1_api.urls)),
url(r'v1/sword/$', views.service_document, name='sword_service_document'),
url(r'', include(v2_api.urls)),
Expand Down
68 changes: 68 additions & 0 deletions storage_service/locations/api/v3/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""Version 3 of the Storage Service API.

The Storage Service exposes the following resources via a consistent HTTP JSON
interface under the path namespace /api/v3/:

- /locations/ --- purpose-specific paths within a /spaces/ resource
- /packages/ --- Information Package (SIP, DIP or AIP)
- /spaces/ --- storage space with behaviour specific to backing system
- /pipelines/ --- an Archivematica instance that is the source of a package

The following resources may be exposed later:

- /file/ --- a file on disk (which is in a package), represented as db row.
- /fsobjects/ --- directories and files on disk, read-only, no database models

All resources have endpoints that follow this pattern::

+-----------------+-------------+----------------------------+------------+
| Purpose | HTTP Method | Path | Method |
+-----------------+-------------+----------------------------+------------+
| Create new | POST | /<cllctn_name>/ | create |
| Create data | GET | /<cllctn_name>/new/ | new |
| Read all | GET | /<cllctn_name>/ | index |
| Read specific | GET | /<cllctn_name>/<id>/ | show |
| Update specific | PUT | /<cllctn_name>/<id>/ | update |
| Update data | GET | /<cllctn_name>/<id>/edit/ | edit |
| Delete specific | DELETE | /<cllctn_name>/<id>/ | delete |
| Search | SEARCH | /<cllctn_name>/ | search |
| Search | POST | /<cllctn_name>/search/ | search |
| Search data | GET | /<cllctn_name>/new_search/ | new_search |
+-----------------+-------------+----------------------------+------------+

.. note:: To remove the search-related routes for a given resource, create a
``'searchable'`` key with value ``False`` in the configuration for the
resource in the ``RESOURCES`` dict. E.g., ``'location': {'searchable':
False}`` will make the /locations/ resource non-searchable.

.. note:: All resources expose the same endpoints. If a resource needs special
treatment, it should be done at the corresponding class level. E.g., if
``POST /packages/`` (creating a package) is special, then do special stuff
in ``resources.py::Packages.create``. Similarly, if packages are indelible,
then ``resources.py::Packages.delete`` should return 404.

"""

from locations.api.v3.remple import API
from locations.api.v3.resources import (
Locations,
Packages,
Spaces,
Pipelines,
)

API_VERSION = '3.0.0'
SERVICE_NAME = 'Archivematica Storage Service'

resources = {
'location': {'resource_cls': Locations},
'package': {'resource_cls': Packages}, # Readonly because of super-class of ``Packages``
'space': {'resource_cls': Spaces},
'pipeline': {'resource_cls': Pipelines},
}

api = API(api_version=API_VERSION, service_name=SERVICE_NAME)
api.register_resources(resources)
urls = api.get_urlpatterns()

__all__ = ('urls', 'api')
14 changes: 14 additions & 0 deletions storage_service/locations/api/v3/remple/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
================================================================================
Remple: REST Simple
================================================================================

Usage::

>>> from remple import API, Resources
>>> class Users(Resources):
... model_cls = User # A Django model class
... schema_cls = UserSchema # A Formencode class
>>> resources = {'user': {'resource_cls': Users}}
>>> api = API(api_version='0.1.0', service_name='User City!')
>>> api.register_resources(resources)
>>> urls = api.get_urlpatterns() # Include thes in Django urlpatterns
31 changes: 31 additions & 0 deletions storage_service/locations/api/v3/remple/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Remple: REST Simple

Usage::

>>> from remple import API, Resources
>>> class Users(Resources):
... model_cls = User # A Django model class
... schema_cls = UserSchema # A Formencode class
>>> resources = {'user': {'resource_cls': Users}}
>>> api = API(api_version='0.1.0', service_name='User City!')
>>> api.register_resources(resources)
>>> urls = api.get_urlpatterns() # Include thes in Django urlpatterns
"""

from __future__ import absolute_import

from .resources import Resources, ReadonlyResources
from .querybuilder import QueryBuilder
from .routebuilder import RouteBuilder as API
from .routebuilder import (
UUID_PATT,
ID_PATT,
get_collection_targeting_regex,
get_member_targeting_regex,
)
from . import utils
from .schemata import ValidModelObject

__all__ = ('API', 'UUID_PATT', 'ID_PATT', 'utils', 'ReadonlyResources',
'QueryBuilder', 'Resources', 'ValidModelObject',
'get_collection_targeting_regex', 'get_member_targeting_regex',)
Loading