Skip to main content

Pyramid REST

Overview

  • 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. HTTP PATCH method: http://tools.ietf.org/html/rfc5789

  2. Resource Scaffolding command;

  3. Links;

  4. Validation;

  5. Pagination;

  6. Automatic resource definition of SQLAlchemy entities;

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

Code/Feedbacks

https://github.com/hadrien/pyramid_rest

Changelog

Development

0.2.8

  • Compatibility with updated zope.interfaces

  • Using last functionality of pyramid_mongokit

  • No more distribute in setup.py

0.2.5

  • Moved mongo connection to pyramid_mongokit.

0.2.4

  • Switch to github.

  • Add support for mongo database:

  • Setting in ini file pyramid_rest.mongo considered true by default

  • MongoConnection is registered to registry

  • Two properties added to request: mongo_connection and mongo_db

  • Mongo connection gets uri from os.environ['MONGO_URI']

  • Database name comes from os.environ['MONGO_DB_NAME']

  • Any resource view with a model_class class attribute with value being a definition of a mongokit.Document can inherit pyramid_rest.mongo.DocumentView to inherit all default actions.

  • Add custom renderer which adapts output format depending on accept headers, format supported are application/json & application/bson

0.1.0

  • Rename ResourceUtility to ResourceConfigurator to make its role clearer.

  • Force human-friendly names for route pattern variables and view callable parameters, e.g. /applications/{application_id}/users/{id} and show(context, request, application_id, id)

  • Remove ability to configure resource separator in resource names: it’s always ‘.’

  • Singular resources via add_singular_resource directive or singular=True keyword argument on Resource or resource_config

  • Moved example from tests directory to root directory: used in test and useful for documentation.

0.0.1

  • Collection resource only

  • Imperative mode via add_resource directive

  • Declarative mode via Resource class

  • Declarative mode view resource_config decorator

Release files for pyramid_rest 0.2.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyramid_rest 0.2.8
File Size Uploaded
pyramid_rest-0.2.8.tar.gz 18.5 kB Details

Release files / pyramid_rest-0.2.8.tar.gz

Download URL pyramid_rest-0.2.8.tar.gz
Size 18.5 kB
Tags Source
SHA-256 checksum
How to use checksums
d9f990bdec7cb2fb54a66d129e72d53b6848aa63bfe0743042eef28213cdd7df
BLAKE2b-256 checksum
How to use checksums
c4a7d825037bf1b4eb267756076574246f9a522c4bea56451b72c8e535facf1e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.2.8 This release

1 release file

0.2.7

1 release file

0.2.6

1 release file

0.2.5

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.0

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page