Skip to main content

Pyramid Rest Extension

Project description

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')
      
      @app_users.index()
      def index(context, request, application_id):
          pass
      
      @app_users.show()
      def show(context, request, application_id, id):
          pass
    3. Declarative using resource_config decorator:

      @resource_config('application.user')
      class AppUsers(object):
      
          def __init__(self, context, request):
              pass
      
          def index(self, application_id):
              return {}
      
          @method_config(renderer='example.mako')
          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. Support for non-collection resource;

  3. Force identifier names.

  4. Resource Scaffolding command;

  5. Custom renderer which adapts response format depending on Accept header;

  6. Links;

  7. Validation;

  8. Pagination;

  9. Automatic resource definition of SQLAlchemy entities;

  10. Have a view parameter in add_resource to override view definition;

Code/Feedbacks

https://bitbucket.org/hadrien/pyramid_rest

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

pyramid_rest-0.0.1.tar.gz (9.6 kB view details)

Uploaded Source

File details

Details for the file pyramid_rest-0.0.1.tar.gz.

File metadata

File hashes

Hashes for pyramid_rest-0.0.1.tar.gz
Algorithm Hash digest
SHA256 b06234982c45ca952b4296e5f0711186cd794d61cb4969da055381ee84220e92
MD5 8d724d3de72335d47ddb0d05e081e730
BLAKE2b-256 c1394b3e5d1e7cc6162f4fa7e0777501933718c233bf8e98ddfe5db54802b878

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