SlideShare a Scribd company logo
1 of 26
REST w Pyramidzie




              Łukasz Oleś
Prostota
 Minimalizm
Dokumentacja
  Szybkość
 Stabilność
Działa na:

●Python 2.6 – 3.3
●PyPy

●Jython

●GAE
REST
              http://autouzupelnij.pl




GET
http://api.autouzupelnij.pl/v1/public/city?term=gli
REST

         (…)/public/city?term=gli




Nazwa konta
REST

         (…)/public/city?term=gli




Nazwa konta      Kontener
REST

         (…)/public/city?term=gli




Nazwa konta      Kontener           Zapytanie
Nowy projekt

      pcreate -t starter api

api
  development.ini
  setup.py
  api
    __init__.py
    views.py
Plik api/__init__.py


from pyramid.config import Configurator

def main(global_config, **settings):
  config = Configurator(settings=settings)
  config.add_route('completion',
                   '/v1/{account}/{container}')
  config.scan()
  return config.make_wsgi_app()



pserve development.ini
Plik api/views.py

from pyramid.view import view_config

@view_config(route_name='completion',
               renderer='json',
               request_method='GET')
def completion(request):
  account = request.matchdict['account']
  container = request.matchdict['container']
  query = request.params.get('term', u'')

  storage = get_storage(account)
  offers = storage.suggest(container, query))
  return offers
Plik api/views.py

@view_config(route_name='completion',
               renderer='json',
               request_method='DELETE',
               permission='edit')
def delete_container(request):
  container = request.matchdict['container']
  account = request.matchdict['account']

  storage = get_storage( account)
  storage.delete_container(container)
Nowy element


Plik api/__init__.py


config.add_route('items',
                '/v1/{account}/{container}/{item}')
Plik api/views.py

@view_config(route_name='items',
               renderer='json',
               request_method='PUT',
               permission='edit')
def add_item(request):
  container = request.matchdict['container']
  account = request.matchdict['account']
  item = request.matchdict['item']

  storage = get_storage(account)
  storage.store_item(container, item)
Walidacja - dodatkowe dane


    {
    ”population” : 20000,
    ”province” : ”slaskie”
    }
Colander
       http://docs.pylonsproject.org/projects/colander



from colander import MappingSchema,
                     SchemaNode, Int, String

class City(MappingSchema):
   province = SchemaNode(String())
   population = SchemaNode(Int())
Plik api/views.py
@view_config(route_name='items',
               renderer='json',
               request_method='PUT',
               permission='edit')
def add_item(request):
  container = request.matchdict['container']
  account = request.matchdict['account']
  item = request.matchdict['item']
  city = City()
  data = city.deserialize(request.json_body)
  storage = get_storage(account)
  storage.store_item(container, item, data)
@view_config(context=colander.Invalid)
def failed_valdation(exc, request):
  err = json.dumps(exc.asdict())
  return HTTPBadRequest(err)
Autoryzacja


http://docs.pylonsproject.org/projects/pyramid/en/
       latest/tutorials/wiki2/authorization.html

  https://ziggurat-foundations.readthedocs.org
Plik api/__init__.py

from api.auth import RootFactory, auth_check

def main(global_config, **settings):
  config = Configurator(settings=settings,
                        root_factory=RootFactory,
                          authentication_policy=
                AuthenticationPolicy(auth_check))
COSR – poziom zaawansowany
     http://en.wikipedia.org/wiki/Cross-origin_resource_sharing




                 JavaScript Ajax
http://autouzupelnij.pl -> http://api.autouzupelnij.pl
COSR – poziom zaawansowany


Access-Control-Allow-Origin: http://autouzupelnij.pl
Access-Control-Allow-Origin: *

Access-Control-Allow-Methods: POST, GET
Access-Control-Allow-Headers: Content-Type
COSR – poziom zaawansowany
Plik api/__init__.py

from pyramid.events import subscriber,
                          NewResponse

@subscriber(NewResponse)
def add_access_list(event):
  event.response.headerlist.append(
            ('Access-Control-Allow-Origin', '*'))
Co dalej?



          Cornice
http://cornice.readthedocs.org/
Pytania




          Łukasz Oleś
          lukaszoles@gmail.com
Dziękuję

       Łukasz Oleś
       lukaszoles@gmail.com

More Related Content

What's hot

20141001 delapsley-oc-openstack-final
20141001 delapsley-oc-openstack-final20141001 delapsley-oc-openstack-final
20141001 delapsley-oc-openstack-final
David Lapsley
 
Анатолий Поляков - Drupal.ajax framework from a to z
Анатолий Поляков - Drupal.ajax framework from a to zАнатолий Поляков - Drupal.ajax framework from a to z
Анатолий Поляков - Drupal.ajax framework from a to z
LEDC 2016
 
Sprout core and performance
Sprout core and performanceSprout core and performance
Sprout core and performance
Yehuda Katz
 

What's hot (20)

Code Igniter 2
Code Igniter 2Code Igniter 2
Code Igniter 2
 
AngularJS - $http & $resource Services
AngularJS - $http & $resource ServicesAngularJS - $http & $resource Services
AngularJS - $http & $resource Services
 
Connecting Content Silos: One CMS, Many Sites With The WordPress REST API
 Connecting Content Silos: One CMS, Many Sites With The WordPress REST API Connecting Content Silos: One CMS, Many Sites With The WordPress REST API
Connecting Content Silos: One CMS, Many Sites With The WordPress REST API
 
Drupal 8 Deep Dive: What It Means for Developers Now that REST Is in Core
Drupal 8 Deep Dive: What It Means for Developers Now that REST Is in Core Drupal 8 Deep Dive: What It Means for Developers Now that REST Is in Core
Drupal 8 Deep Dive: What It Means for Developers Now that REST Is in Core
 
AngularJS $http Interceptors (Explanation and Examples)
AngularJS $http Interceptors (Explanation and Examples)AngularJS $http Interceptors (Explanation and Examples)
AngularJS $http Interceptors (Explanation and Examples)
 
Intorduction of Playframework
Intorduction of PlayframeworkIntorduction of Playframework
Intorduction of Playframework
 
Client-side Rendering with AngularJS
Client-side Rendering with AngularJSClient-side Rendering with AngularJS
Client-side Rendering with AngularJS
 
20141001 delapsley-oc-openstack-final
20141001 delapsley-oc-openstack-final20141001 delapsley-oc-openstack-final
20141001 delapsley-oc-openstack-final
 
Silex Cheat Sheet
Silex Cheat SheetSilex Cheat Sheet
Silex Cheat Sheet
 
Phoenix + Reactで 社内システムを 密かに作ってる
Phoenix + Reactで 社内システムを 密かに作ってるPhoenix + Reactで 社内システムを 密かに作ってる
Phoenix + Reactで 社内システムを 密かに作ってる
 
Анатолий Поляков - Drupal.ajax framework from a to z
Анатолий Поляков - Drupal.ajax framework from a to zАнатолий Поляков - Drupal.ajax framework from a to z
Анатолий Поляков - Drupal.ajax framework from a to z
 
Web Components With Rails
Web Components With RailsWeb Components With Rails
Web Components With Rails
 
Presentation
PresentationPresentation
Presentation
 
JavaScript JQUERY AJAX
JavaScript JQUERY AJAXJavaScript JQUERY AJAX
JavaScript JQUERY AJAX
 
实战Ecos
实战Ecos实战Ecos
实战Ecos
 
Diving into php
Diving into phpDiving into php
Diving into php
 
Drupal 7 Entity & Entity API
Drupal 7 Entity & Entity APIDrupal 7 Entity & Entity API
Drupal 7 Entity & Entity API
 
Using the new WordPress REST API
Using the new WordPress REST APIUsing the new WordPress REST API
Using the new WordPress REST API
 
Jsp
JspJsp
Jsp
 
Sprout core and performance
Sprout core and performanceSprout core and performance
Sprout core and performance
 

Similar to Pyramid REST

jsSaturday - PhoneGap and jQuery Mobile for SharePoint 2013
jsSaturday - PhoneGap and jQuery Mobile for SharePoint 2013jsSaturday - PhoneGap and jQuery Mobile for SharePoint 2013
jsSaturday - PhoneGap and jQuery Mobile for SharePoint 2013
Kiril Iliev
 
前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说
Ting Lv
 
Gae Meets Django
Gae Meets DjangoGae Meets Django
Gae Meets Django
fool2nd
 

Similar to Pyramid REST (20)

Reduxing like a pro
Reduxing like a proReduxing like a pro
Reduxing like a pro
 
jsSaturday - PhoneGap and jQuery Mobile for SharePoint 2013
jsSaturday - PhoneGap and jQuery Mobile for SharePoint 2013jsSaturday - PhoneGap and jQuery Mobile for SharePoint 2013
jsSaturday - PhoneGap and jQuery Mobile for SharePoint 2013
 
Denys Serhiienko "ASGI in depth"
Denys Serhiienko "ASGI in depth"Denys Serhiienko "ASGI in depth"
Denys Serhiienko "ASGI in depth"
 
Using WordPress as your application stack
Using WordPress as your application stackUsing WordPress as your application stack
Using WordPress as your application stack
 
Authenticating and Securing Node.js APIs
Authenticating and Securing Node.js APIsAuthenticating and Securing Node.js APIs
Authenticating and Securing Node.js APIs
 
Security enforcement of Java Microservices with Apiman & Keycloak
Security enforcement of Java Microservices with Apiman & KeycloakSecurity enforcement of Java Microservices with Apiman & Keycloak
Security enforcement of Java Microservices with Apiman & Keycloak
 
Intoduction on Playframework
Intoduction on PlayframeworkIntoduction on Playframework
Intoduction on Playframework
 
I Phone On Rails
I Phone On RailsI Phone On Rails
I Phone On Rails
 
Amplify를 통해 클라우드 기반 모바일 앱 개발하기 - 박태성(IDEASAM) :: AWS Community Day 2020
Amplify를 통해 클라우드 기반 모바일 앱 개발하기 - 박태성(IDEASAM) :: AWS Community Day 2020Amplify를 통해 클라우드 기반 모바일 앱 개발하기 - 박태성(IDEASAM) :: AWS Community Day 2020
Amplify를 통해 클라우드 기반 모바일 앱 개발하기 - 박태성(IDEASAM) :: AWS Community Day 2020
 
前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说
 
Pyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web appsPyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web apps
 
Silex Cheat Sheet
Silex Cheat SheetSilex Cheat Sheet
Silex Cheat Sheet
 
Django
DjangoDjango
Django
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
Finch.io - Purely Functional REST API with Finagle
Finch.io - Purely Functional REST API with FinagleFinch.io - Purely Functional REST API with Finagle
Finch.io - Purely Functional REST API with Finagle
 
YAP / Open Mail Overview
YAP / Open Mail OverviewYAP / Open Mail Overview
YAP / Open Mail Overview
 
Gae Meets Django
Gae Meets DjangoGae Meets Django
Gae Meets Django
 
How to implement authorization in your backend with AWS IAM
How to implement authorization in your backend with AWS IAMHow to implement authorization in your backend with AWS IAM
How to implement authorization in your backend with AWS IAM
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
 
Advanced #2 networking
Advanced #2   networkingAdvanced #2   networking
Advanced #2 networking
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 

Pyramid REST

  • 1. REST w Pyramidzie Łukasz Oleś
  • 2.
  • 3. Prostota Minimalizm Dokumentacja Szybkość Stabilność
  • 4. Działa na: ●Python 2.6 – 3.3 ●PyPy ●Jython ●GAE
  • 5. REST http://autouzupelnij.pl GET http://api.autouzupelnij.pl/v1/public/city?term=gli
  • 6. REST (…)/public/city?term=gli Nazwa konta
  • 7. REST (…)/public/city?term=gli Nazwa konta Kontener
  • 8. REST (…)/public/city?term=gli Nazwa konta Kontener Zapytanie
  • 9. Nowy projekt pcreate -t starter api api development.ini setup.py api __init__.py views.py
  • 10. Plik api/__init__.py from pyramid.config import Configurator def main(global_config, **settings): config = Configurator(settings=settings) config.add_route('completion', '/v1/{account}/{container}') config.scan() return config.make_wsgi_app() pserve development.ini
  • 11. Plik api/views.py from pyramid.view import view_config @view_config(route_name='completion', renderer='json', request_method='GET') def completion(request): account = request.matchdict['account'] container = request.matchdict['container'] query = request.params.get('term', u'') storage = get_storage(account) offers = storage.suggest(container, query)) return offers
  • 12. Plik api/views.py @view_config(route_name='completion', renderer='json', request_method='DELETE', permission='edit') def delete_container(request): container = request.matchdict['container'] account = request.matchdict['account'] storage = get_storage( account) storage.delete_container(container)
  • 13. Nowy element Plik api/__init__.py config.add_route('items', '/v1/{account}/{container}/{item}')
  • 14. Plik api/views.py @view_config(route_name='items', renderer='json', request_method='PUT', permission='edit') def add_item(request): container = request.matchdict['container'] account = request.matchdict['account'] item = request.matchdict['item'] storage = get_storage(account) storage.store_item(container, item)
  • 15. Walidacja - dodatkowe dane { ”population” : 20000, ”province” : ”slaskie” }
  • 16. Colander http://docs.pylonsproject.org/projects/colander from colander import MappingSchema, SchemaNode, Int, String class City(MappingSchema): province = SchemaNode(String()) population = SchemaNode(Int())
  • 17. Plik api/views.py @view_config(route_name='items', renderer='json', request_method='PUT', permission='edit') def add_item(request): container = request.matchdict['container'] account = request.matchdict['account'] item = request.matchdict['item'] city = City() data = city.deserialize(request.json_body) storage = get_storage(account) storage.store_item(container, item, data)
  • 18. @view_config(context=colander.Invalid) def failed_valdation(exc, request): err = json.dumps(exc.asdict()) return HTTPBadRequest(err)
  • 19. Autoryzacja http://docs.pylonsproject.org/projects/pyramid/en/ latest/tutorials/wiki2/authorization.html https://ziggurat-foundations.readthedocs.org
  • 20. Plik api/__init__.py from api.auth import RootFactory, auth_check def main(global_config, **settings): config = Configurator(settings=settings, root_factory=RootFactory, authentication_policy= AuthenticationPolicy(auth_check))
  • 21. COSR – poziom zaawansowany http://en.wikipedia.org/wiki/Cross-origin_resource_sharing JavaScript Ajax http://autouzupelnij.pl -> http://api.autouzupelnij.pl
  • 22. COSR – poziom zaawansowany Access-Control-Allow-Origin: http://autouzupelnij.pl Access-Control-Allow-Origin: * Access-Control-Allow-Methods: POST, GET Access-Control-Allow-Headers: Content-Type
  • 23. COSR – poziom zaawansowany Plik api/__init__.py from pyramid.events import subscriber, NewResponse @subscriber(NewResponse) def add_access_list(event): event.response.headerlist.append( ('Access-Control-Allow-Origin', '*'))
  • 24. Co dalej? Cornice http://cornice.readthedocs.org/
  • 25. Pytania Łukasz Oleś lukaszoles@gmail.com
  • 26. Dziękuję Łukasz Oleś lukaszoles@gmail.com