Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: 0.1.0

Fetching latest commit…

Cannot retrieve the latest commit at this time


Pyramid REST

  • First draft of a pyramid extension to build RESTful web application.

  • Features included:

    • resource definition which configure routes/views, i.e:

      • a resource 'application':

        • route [GET/POST] /applications
        • route [GET/DELETE/PUT] /applications/{application_id}
        • route GET /applications/{application_id}/new
        • route GET /applications/{application_id}/edit
      • a resource 'application.user':

        • route [GET/POST] /applications/{application_id}/users
        • route [GET/DELETE/PUT] /applications/{application_id}/users/{user_id}
        • route GET /applications/{application_id}/users/new
        • route GET /applications/{application_id}/users/edit
      • a singular resource 'application.user.score':

        • route [GET/PUT] /applications/{application_id}/users/{user_id}/score
        • route GET /applications/{application_id}/users/{user_id}/score/edit
    • resources are added to config introspector and related to their routes,views, sub-resource and parent resource;

    • end user defines REST methods (index, create, show, update, delete, new, edit);

    • by default:

      • HTTP 405 is returned for any method not provided;
      • permissions 'index, create, show, update, delete, new, edit' are associated to respective method;
  • 3 ways to configure resource:

    1. Imperative using config.add_resource, it will associate class in views module to resource

      config.add_resource('application')       # .views.applications:ApplicationsView
      config.add_resource('application.user')  # .views.application_users:ApplicationUsersView
    2. Declarative using Resource class (cornice style):

      app_users = Resource('application.user')
      def index(context, request, application_id):
      def show(context, request, application_id, id):
    3. Declarative using resource_config decorator:

      class AppUsers(object):
          def __init__(self, context, request):
          def index(self, application_id):
              return {}
          def edit(self, application_id, id):
              return {}

What next?

  1. Url generation:
    • request.rest_resource_url as resource_url is taken
    • request.rest_resource_path as resource_path is taken
  2. Resource Scaffolding command;
  3. Custom renderer which adapts response format depending on Accept header;
  4. Links;
  5. Validation;
  6. Pagination;
  7. Automatic resource definition of SQLAlchemy entities;
  8. Have a view parameter in add_resource to override view definition;


Something went wrong with that request. Please try again.