Code Monkey home page Code Monkey logo

pyramid_rest's Introduction

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. Security
  2. HTTP PATCH method: http://tools.ietf.org/html/rfc5789
  3. Resource Scaffolding command;
  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;

Code/Feedbacks

https://github.com/hadrien/pyramid_rest

pyramid_rest's People

Contributors

hadrien avatar merwok avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.