SlideShare une entreprise Scribd logo
1  sur  118
Télécharger pour lire hors ligne
Django Apps to Services
Craig Kerstiens
   @craigkerstiens work at @heroku
Django
Project   A collection of configuration and apps for a particular Website.




                                                         (per Django Project)
Django
Project   A collection of configuration and apps for a particular Website.



App       A web application that does something. I.e. Weblog, Poll, Ticket
          system




                                                         (per Django Project)
Table
Table                   Table
                                Table
                        Table           Table
                Table
                                Table
                                        Table
                Table
Table
                        Table   Table

                Table
Table
                        Table
                Table           Table

                        Table           Table
        Table
Table
Table                   Table
                                Table
                        Table           Table
                Table
                                Table
                                        Table
                Table
Table
                        Table   Table

                Table
Table
                        Table
                Table           Table

                        Table           Table
        Table
Table
Table                   Table
                                Table



                                   p
                        Table           Table
                Table


                                 p
                                Table


                                A
                                        Table
                Table
Table
                        Table   Table

                Table
Table
                        Table
                Table           Table

                        Table           Table
        Table
Monolithic Monster
Monolithic Monster
$ ls mysite
models.py
views.py
forms.py
admin.py
Monolithic Monster
$ ls mysite   $ wc -l models.py
models.py           2557 models.py
views.py      $ wc -l view.spy
forms.py            14241 views.py
admin.py
Monolithic Monster
 $ ls mysite                  $ wc -l models.py
 models.py                          2557 models.py
 views.py                     $ wc -l view.spy
 forms.py                           14241 views.py
 admin.py

http://www.slideshare.net/jacobian/the-best-and-worst-of-django
Within Django
Within Django
Project
Within Django
Project

     App

     App

     App
Within Django
Project

   Tickets
     App

     FAQ
     App

  FaqCreator
      App
Within Django
                cd myproject && find .
                 manage.py
Project          requirements.txt
                 settings.py
                 urls.py
                 ./faq/admin.py
                 ./faq/forms.py
   Tickets
     App         ./faq/models.py
                 ./faq/urls.py
                 ./faq/views.py
                 ./faqcreator/admin.py
     FAQ
     App         ./faqcreator/forms.py
                 ./faqcreator/models.py
                 ./faqcreator/urls.py
                 ./faqcreator/views.py
                 ./tickets/admin.py
  FaqCreator
      App        ./tickets/forms.py
                 ./tickets/models.py
                 ./tickets/urls.py
                 ./tickets/views.py
Reusability
cd myproject && find .
                         Reusability
cd myproject && find .
                          Reusability
 manage.py
 requirements.txt
 settings.py
 urls.py
 ./faq/admin.py
 ./faq/forms.py
 ./faq/models.py
 ./faq/urls.py
 ./faq/views.py
 ./faqcreator/admin.py
 ./faqcreator/forms.py
 ./faqcreator/models.py
 ./faqcreator/urls.py
 ./faqcreator/views.py
 ./tickets/admin.py
 ./tickets/forms.py
 ./tickets/models.py
 ./tickets/urls.py
 ./tickets/views.py
cd myproject && find .
                          Reusability
                                   cd myproject && find .
 manage.py
 requirements.txt                   manage.py
 settings.py                        requirements.txt
 urls.py                            settings.py
 ./faq/admin.py                     urls.py


                             -->
 ./faq/forms.py
 ./faq/models.py                   cat myproject/requirements.txt
 ./faq/urls.py
 ./faq/views.py                     faq==0.1
 ./faqcreator/admin.py              faqcreator==0.1
 ./faqcreator/forms.py              tickets==0.1
 ./faqcreator/models.py
 ./faqcreator/urls.py
 ./faqcreator/views.py
 ./tickets/admin.py
 ./tickets/forms.py
 ./tickets/models.py
 ./tickets/urls.py
 ./tickets/views.py
REUSABILITY means faster features due to DRY
(Don’t Repeat Yourself )
REUSABILITY means faster features due to DRY
(Don’t Repeat Yourself )

REUSABILITY does not always mean SCALABILITY
or MAINTAINABILITY
Django
Project   A collection of configuration and apps for a particular Website.



App       A web application that does something. I.e. Weblog, Poll, Ticket
          system




                                                         (per Django Project)
Django
Project   A collection of configuration and apps for a particular Website.



App       A web application that does something. I.e. Weblog, Poll, Ticket
          system



Service   Method of communication over the web.
          Web APIs allow combination of multiple services
Tech imitate Teams
Project          Company

   Tickets
     App               Support

     FAQ
     App            Knowledge Base

  FaqCreator
      App
Teams
   Support


Knowledge Base
Teams Grow
     App
   Support


     App
Knowledge Base
Teams Grow
     App
   Support


     App
Knowledge Base


   Billing
Teams Grow
     App
   Support         Marketing


     App
Knowledge Base


   Billing
Teams Grow
     App
   Support         Marketing      API


     App
Knowledge Base     Analytics   Front End


   Billing          Mobile      Social
Apps Grow
     App
   Support         Marketing      API


          p  s
     App
     A  p
Knowledge Base     Analytics   Front End

3 App
   Billing          Mobile      Social
Apps Grow
     App
   Support
                      p
                    App
                        s
                     Marketing     App
                                   API



                  A p
                 9
     App
Knowledge Base      App
                     Analytics      App
                                 Front End


    App
   Billing             App
                      Mobile       App
                                  Social
Apps Grow
   Support
                      p s
                     Marketing      API


                   Ap        se
Knowledge Base
                 9 deb     a
                     Analytics   Front End


   Billing

                  C o Mobile      Social



                 1
SOA To the Rescue
SOA To the Rescue
SOA To the Rescue


  Photo by Paul Downey (psd on flickr)
Service
Defined contract for communicating
Service
Defined contract for communicating

$ curl -O $FAQ_API/create/
      -X “question=my question source=123”
In Python
In Python
data = {
 ‘question’: “my question”,
 ‘source’: 123
}
requests.POST(os.environ[‘FAQ_API’] + ‘/
create/’, data=data)
More than just API
More than just API
www.google.com
More than just API
www.google.com
mail.google.com
More than just API
www.google.com
mail.google.com
calendar.google.com
More than just API
www.google.com
mail.google.com
calendar.google.com
..............google.com
Types of Services
Types of Services
site
Types of Services
site
subdomain
Types of Services
site
subdomain
API
Types of Services
site
subdomain
API
   - no auth required
Types of Services
site
subdomain
API
   - no auth required
   - API auth required
Types of Services
site
subdomain
API
   - no auth required
   - API auth required
   - user auth required
Where to Start
     App
   Support              App
                     Marketing      App
                                    API


     App
Knowledge Base          App
                     Analytics       App
                                  Front End


    App
   Billing             App
                      Mobile        App
                                   Social
Where to Start
     App
   Support              App
                     Marketing       API


     App
Knowledge Base       Analytics    Front End


   Billing            Mobile        App
                                   Social
1 Javascript
Many pages
LA POSTA
Within Django
                cd myproject && find .
                 manage.py
Project          requirements.txt
                 settings.py
                 urls.py
                 ./faq/admin.py
                 ./faq/forms.py
   Tickets
     App         ./faq/models.py
                 ./faq/urls.py
                 ./faq/views.py
                 ./faqcreator/admin.py
     FAQ
     App         ./faqcreator/forms.py
                 ./faqcreator/models.py
                 ./faqcreator/urls.py
                 ./faqcreator/views.py
                 ./tickets/admin.py
  FaqCreator
      App        ./tickets/forms.py
                 ./tickets/models.py
                 ./tickets/urls.py
                 ./tickets/views.py
Apps Depend on Other Apps
Apps Depend on Other Apps
faq creator
Apps Depend on Other Apps
faq creator
        faq app
Apps Depend on Other Apps
faq creator
        faq app

ticket
Apps Depend on Other Apps
faq creator
        faq app

ticket
         faq app
Apps Depend on Other Apps
faq creator
        faq app version == 0.1

ticket
         faq app version == 0.2
Apps Depend on Other Apps
pip install faq==0.1
pip install faq==0.2
pip freeze
faq==0.2
Apps Depend on Other Apps
faq creator
        faq app version == 0.1

ticket
         faq app version == 0.2
Back to APIs
What’s a service
Provider   API_HOST= http://127.0.0.1
What’s a service
Provider   API_HOST= http://127.0.0.1



Endpoint   /v1/create/
What’s a service
Provider   API_HOST= http://127.0.0.1



Endpoint   /v1/create/



Contract   {
               ‘question’: ‘foo bar’,
               ‘source’: 123
               }
App
App
URLs   Views   Models
App
URLs       Views      Models

           Service
Provider   Endpoint   Contract
A SERVICE means REUSABILITY
and enables SCALABILITY and
MAINTAINABILITY
Where to start
Where to start
1. If you’re monolithic, break up the apps first
Where to start
1. If you’re monolithic, break up the apps first
2. Port something that doesn’t require user
Where to start
1. If you’re monolithic, break up the apps first
2. Port something that doesn’t require user
3. Port where you have many dependencies
Porting an App
                     models.py
class Faq(models.Model):
  title = models.CharField(max_length=100)
  source = models.IntegerField(blank=True, null=True)
  description = models.TextField()
  solution = models.TextField()

  def __unicode__(self):
    return self.title
Porting an App
             faqcreator/views.py
from faq.models import faq

i = Faq(title=‘foo’, description=‘bar’, solution=’la posta’)
i.save()
Turn it into an API
Turn it into an API
1. pip install django-tastypie
Turn it into an API
1. pip install django-tastypie
2. add tastypie to INSTALLED_APPS
Turn it into an API
1. pip install django-tastypie
2. add tastypie to INSTALLED_APPS
3. define your APIs
Create your API
from
                                        faq/api.py
       tastypie.resources import ModelResource
from   faq.models import Faq
from   django.contrib.auth.models import User
from   tastypie.authentication import BasicAuthentication, DjangoAuthorization
from   tastypie.authorization import Authorization

class FaqResource(ModelResource):
    class Meta:
        queryset = Faq.objects.all()
        resource_name = 'faq'
        list_allowed_methods = ['get', 'post']
        authentication = BasicAuthentication()
        authorization = Authorization()

   def obj_create(self, bundle, request=None, **kwargs):
       return super(FaqResource, self).obj_create(bundle, request, user=request.user)

   def apply_authorization_limits(self, request, object_list):
       return object_list.filter(user=request.user)
Create your API
                             api.py
class FaqResource(ModelResource):
  class Meta:
     queryset = Faq.objects.all()
     resource_name = 'faq'
     list_allowed_methods = ['get', 'post']
     authentication = BasicAuthentication()
     authorization = Authorization()

  def obj_create(self, bundle, request=None, **kwargs):
    return super(FaqResource, self).obj_create(
         bundle, request, user=request.user)

  def apply_authorization_limits(self, request, object_list):
    return object_list.filter(user=request.user)
Create your API
                             api.py
class FaqResource(ModelResource):
  class Meta:
     queryset = Faq.objects.all()
     resource_name = 'faq'
     list_allowed_methods = ['get', 'post']
     authentication = BasicAuthentication()
     authorization = Authorization()

  def obj_create(self, bundle, request=None, **kwargs):
    return super(FaqResource, self).obj_create(
         bundle, request, user=request.user)

  def apply_authorization_limits(self, request, object_list):
    return object_list.filter(user=request.user)
Create your API
                             api.py
class FaqResource(ModelResource):
  class Meta:
     queryset = Faq.objects.all()
     resource_name = 'faq'
     list_allowed_methods = ['get', 'post']
     authentication = BasicAuthentication()
     authorization = Authorization()

  def obj_create(self, bundle, request=None, **kwargs):
    return super(FaqResource, self).obj_create(
         bundle, request, user=request.user)

  def apply_authorization_limits(self, request, object_list):
    return object_list.filter(user=request.user)
Create your API
                             api.py
class FaqResource(ModelResource):
  class Meta:
     queryset = Faq.objects.all()
     resource_name = 'faq'
     list_allowed_methods = ['get', 'post']
     authentication = BasicAuthentication()
     authorization = Authorization()

  def obj_create(self, bundle, request=None, **kwargs):
    return super(FaqResource, self).obj_create(
         bundle, request, user=request.user)

  def apply_authorization_limits(self, request, object_list):
    return object_list.filter(user=request.user)
Create your API
                             api.py
class FaqResource(ModelResource):
  class Meta:
     queryset = Faq.objects.all()
     resource_name = 'faq'
     list_allowed_methods = ['get', 'post']
     authentication = BasicAuthentication()
     authorization = Authorization()

  def obj_create(self, bundle, request=None, **kwargs):
    return super(FaqResource, self).obj_create(
         bundle, request, user=request.user)

  def apply_authorization_limits(self, request, object_list):
    return object_list.filter(user=request.user)
Create your API
                             api.py
class FaqResource(ModelResource):
  class Meta:
     queryset = Faq.objects.all()
     resource_name = 'faq'
     list_allowed_methods = ['get', 'post']
     authentication = BasicAuthentication()
     authorization = Authorization()

  def obj_create(self, bundle, request=None, **kwargs):
    return super(FaqResource, self).obj_create(
         bundle, request, user=request.user)

  def apply_authorization_limits(self, request, object_list):
    return object_list.filter(user=request.user)
Create your API
                         urls.py
from faq.api import FaqResource
from tastypie.api import Api

v1_api = Api(api_name='v1')
v1_api.register(FaqResource())

urlpatterns = patterns('',
    url(r'^api/', include(v1_api.urls)),
)
Use your API
curl -H "Content-Type: application/json"
     --user admin:testing
     -X POST
     --data
       '{"title": "New FAQ",
         "source": "1",
         "description": "foo",
         "solution": "bar"}'
     http://127.0.0.1:8000/api/v1/faq/
Use it in Python
Use it in Python
data = {
  'title': 'New FAQ',
  'source': '1',
  'description': 'foo',
  'solution': 'bar'
}

r = requests.post(os.environ[‘FAQ_API’] + "api/v1/faq/",
  data=data,
  auth=('admin', 'testing'))
Version Bump
Version Bump
data = {
  'title': 'New FAQ',
  'source': '1',
  'description': 'foo',
  'solution': 'bar',
  'related': ['123', '456']
}

r = requests.post(os.environ[‘FAQ_API’] + "api/v2/faq/",
  data=data,
  auth=('admin', 'testing'))
Version Bump
Version Bump
data = {
  'title': 'New FAQ',
  'source': '1',
  'description': 'foo',
  'solution': 'bar',
  'related': ['123', '456']
}

r = requests.post(os.environ[‘FAQ_API’] + "api/v2/faq/",
  data=data,
  auth=('admin', 'testing'))
In our Application
faq_creator/views.py



  ticket/views.py
In our Application
           faq_creator/views.py
r = requests.post(os.environ[‘FAQ_API’] + "api/v2/faq/",
  data=data,
  auth=('admin', 'testing'))


               ticket/views.py
r = requests.post(os.environ[‘FAQ_API’] + "api/v1/faq/",
  data=data,
  auth=('admin', 'testing'))
cd myproject && find .
                          Reusability
                                   cd myproject && find .
 manage.py
 requirements.txt                   manage.py
 settings.py                        requirements.txt
 urls.py                            settings.py
 ./faq/admin.py                     urls.py


                             -->
 ./faq/forms.py
 ./faq/models.py                   cat myproject/requirements.txt
 ./faq/urls.py
 ./faq/views.py                     faq==0.1
 ./faqcreator/admin.py              faqcreator==0.1
 ./faqcreator/forms.py              tickets==0.1
 ./faqcreator/models.py
 ./faqcreator/urls.py
 ./faqcreator/views.py
 ./tickets/admin.py
 ./tickets/forms.py
 ./tickets/models.py
 ./tickets/urls.py
 ./tickets/views.py
Maintainability/Scalability/Agility
cd myproject && find .                 ls projects
 manage.py                              faq-service
 requirements.txt                       myproject
 settings.py                           cd faq-service && find .
 urls.py                                manage.py
                                        requirements.txt
cat myproject/requirements.txt
 faq==0.1
                                 -->    settings.py
                                        urls.py
                                       cd myproject && find .
 faqcreator==0.1
 tickets==0.1                           manage.py
                                        requirements.txt
                                        settings.py
                                        urls.py
                                       cat myproject/requirements.txt
                                        faqcreator==0.1
                                        tickets==0.1
Maintainability/Scalability/Agility
Maintainability/Scalability/Agility
                  Faq Project
                   - Its own Django project
                   - 1 Django app
                   - Own database
                   - Own deployment
Maintainability/Scalability/Agility
My Project                    Faq Project
 - Contained Django Project    - Its own Django project
 - 2 Django apps               - 1 Django app
 - Own database                - Own database
 - Own deployment              - Own deployment
Take aways
Take aways
1. Start non-critical (Cheat)
2. Create services where theres app reuse
3. Create services where theres pain
4. Start small
Others
Others
1. Expect APIs to fail
2. Flask is great for APIs
3. Make it easy to setup/test
Fin.
  Resources
http://www.craigkerstiens.com
http://bit.ly/djangoappstoservices/
http://www.12factor.net
http://github.com/craigkerstiens/

Contenu connexe

Tendances

With a Mighty Hammer
With a Mighty HammerWith a Mighty Hammer
With a Mighty HammerBen Scofield
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overviewYehuda Katz
 
Let's write secure Drupal code! DUG Belgium - 08/08/2019
Let's write secure Drupal code! DUG Belgium - 08/08/2019Let's write secure Drupal code! DUG Belgium - 08/08/2019
Let's write secure Drupal code! DUG Belgium - 08/08/2019Balázs Tatár
 
Let's write secure drupal code! - Drupal Camp Pannonia 2019
Let's write secure drupal code! - Drupal Camp Pannonia 2019Let's write secure drupal code! - Drupal Camp Pannonia 2019
Let's write secure drupal code! - Drupal Camp Pannonia 2019Balázs Tatár
 
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Mike Schinkel
 
Building Cloud Castles
Building Cloud CastlesBuilding Cloud Castles
Building Cloud CastlesBen Scofield
 
jQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & CompressionjQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & CompressionPaul Irish
 
A Little Backbone For Your App
A Little Backbone For Your AppA Little Backbone For Your App
A Little Backbone For Your AppLuca Mearelli
 
Let's write secure Drupal code! - Drupal Camp Poland 2019
Let's write secure Drupal code! - Drupal Camp Poland 2019Let's write secure Drupal code! - Drupal Camp Poland 2019
Let's write secure Drupal code! - Drupal Camp Poland 2019Balázs Tatár
 
Plugin jQuery, Design Patterns
Plugin jQuery, Design PatternsPlugin jQuery, Design Patterns
Plugin jQuery, Design PatternsRobert Casanova
 
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014Hardcore URL Routing for WordPress - WordCamp Atlanta 2014
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014Mike Schinkel
 
Zend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolZend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolGordon Forsythe
 
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Let's write secure Drupal code! - DrupalCamp Oslo, 2018Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Let's write secure Drupal code! - DrupalCamp Oslo, 2018Balázs Tatár
 
And now you have two problems. Ruby regular expressions for fun and profit by...
And now you have two problems. Ruby regular expressions for fun and profit by...And now you have two problems. Ruby regular expressions for fun and profit by...
And now you have two problems. Ruby regular expressions for fun and profit by...Codemotion
 
Django REST Framework
Django REST FrameworkDjango REST Framework
Django REST FrameworkLoad Impact
 
Things Your Mother Didnt Tell You About Bundle Configurations - Symfony Live…
Things Your Mother Didnt Tell You About Bundle Configurations - Symfony Live…Things Your Mother Didnt Tell You About Bundle Configurations - Symfony Live…
Things Your Mother Didnt Tell You About Bundle Configurations - Symfony Live…D
 
Things Your Mother Didn't Tell You About Bundle Configurations - Symfony Live...
Things Your Mother Didn't Tell You About Bundle Configurations - Symfony Live...Things Your Mother Didn't Tell You About Bundle Configurations - Symfony Live...
Things Your Mother Didn't Tell You About Bundle Configurations - Symfony Live...D
 

Tendances (20)

With a Mighty Hammer
With a Mighty HammerWith a Mighty Hammer
With a Mighty Hammer
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 
Let's write secure Drupal code! DUG Belgium - 08/08/2019
Let's write secure Drupal code! DUG Belgium - 08/08/2019Let's write secure Drupal code! DUG Belgium - 08/08/2019
Let's write secure Drupal code! DUG Belgium - 08/08/2019
 
Let's write secure drupal code! - Drupal Camp Pannonia 2019
Let's write secure drupal code! - Drupal Camp Pannonia 2019Let's write secure drupal code! - Drupal Camp Pannonia 2019
Let's write secure drupal code! - Drupal Camp Pannonia 2019
 
Assetic (OSCON)
Assetic (OSCON)Assetic (OSCON)
Assetic (OSCON)
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
 
Building Cloud Castles
Building Cloud CastlesBuilding Cloud Castles
Building Cloud Castles
 
jQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & CompressionjQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & Compression
 
A Little Backbone For Your App
A Little Backbone For Your AppA Little Backbone For Your App
A Little Backbone For Your App
 
Let's write secure Drupal code! - Drupal Camp Poland 2019
Let's write secure Drupal code! - Drupal Camp Poland 2019Let's write secure Drupal code! - Drupal Camp Poland 2019
Let's write secure Drupal code! - Drupal Camp Poland 2019
 
Plugin jQuery, Design Patterns
Plugin jQuery, Design PatternsPlugin jQuery, Design Patterns
Plugin jQuery, Design Patterns
 
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014Hardcore URL Routing for WordPress - WordCamp Atlanta 2014
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014
 
Zend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolZend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_Tool
 
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Let's write secure Drupal code! - DrupalCamp Oslo, 2018Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
 
And now you have two problems. Ruby regular expressions for fun and profit by...
And now you have two problems. Ruby regular expressions for fun and profit by...And now you have two problems. Ruby regular expressions for fun and profit by...
And now you have two problems. Ruby regular expressions for fun and profit by...
 
Django REST Framework
Django REST FrameworkDjango REST Framework
Django REST Framework
 
Things Your Mother Didnt Tell You About Bundle Configurations - Symfony Live…
Things Your Mother Didnt Tell You About Bundle Configurations - Symfony Live…Things Your Mother Didnt Tell You About Bundle Configurations - Symfony Live…
Things Your Mother Didnt Tell You About Bundle Configurations - Symfony Live…
 
Things Your Mother Didn't Tell You About Bundle Configurations - Symfony Live...
Things Your Mother Didn't Tell You About Bundle Configurations - Symfony Live...Things Your Mother Didn't Tell You About Bundle Configurations - Symfony Live...
Things Your Mother Didn't Tell You About Bundle Configurations - Symfony Live...
 
Drupal, meet Assetic
Drupal, meet AsseticDrupal, meet Assetic
Drupal, meet Assetic
 

En vedette

Multi Tenancy With Python and Django
Multi Tenancy With Python and DjangoMulti Tenancy With Python and Django
Multi Tenancy With Python and Djangoscottcrespo
 
Postgres performance for humans
Postgres performance for humansPostgres performance for humans
Postgres performance for humansCraig Kerstiens
 
Developing Software As A Service App with Python & Django
Developing Software As A Service App with Python & DjangoDeveloping Software As A Service App with Python & Django
Developing Software As A Service App with Python & DjangoAllan Mangune
 
SaaSy maps - using django-tenants and geodjango to provide web-gis software-a...
SaaSy maps - using django-tenants and geodjango to provide web-gis software-a...SaaSy maps - using django-tenants and geodjango to provide web-gis software-a...
SaaSy maps - using django-tenants and geodjango to provide web-gis software-a...Anusha Chickermane
 
Django multi-tier
Django multi-tierDjango multi-tier
Django multi-tiersmirolo
 
Django Multi-DB in Anger
Django Multi-DB in AngerDjango Multi-DB in Anger
Django Multi-DB in AngerLoren Davie
 
ZCA: A component architecture for Python
ZCA: A component architecture for PythonZCA: A component architecture for Python
ZCA: A component architecture for PythonTimo Stollenwerk
 
LCNUG 2015 - what's new for agile teams in TFS 2015
LCNUG 2015 -  what's new for agile teams in TFS 2015LCNUG 2015 -  what's new for agile teams in TFS 2015
LCNUG 2015 - what's new for agile teams in TFS 2015Angela Dugan
 
Dev/Test Scenarios in the DevOps World
Dev/Test Scenarios in the DevOps WorldDev/Test Scenarios in the DevOps World
Dev/Test Scenarios in the DevOps WorldPranav Ainavolu
 
Global Windows Azure Bootcamp : Samuel et Emilien Pécoul, Florent Pelet Legac...
Global Windows Azure Bootcamp : Samuel et Emilien Pécoul, Florent Pelet Legac...Global Windows Azure Bootcamp : Samuel et Emilien Pécoul, Florent Pelet Legac...
Global Windows Azure Bootcamp : Samuel et Emilien Pécoul, Florent Pelet Legac...MUG-Lyon Microsoft User Group
 
Driven Development - Closing the Loop on Scrum
Driven Development - Closing the Loop on ScrumDriven Development - Closing the Loop on Scrum
Driven Development - Closing the Loop on ScrumAdam Englander
 
Sofware Fora de Séria 2016 - Implementando realtime no frontend
Sofware Fora de Séria 2016 - Implementando realtime no frontendSofware Fora de Séria 2016 - Implementando realtime no frontend
Sofware Fora de Séria 2016 - Implementando realtime no frontendWilliam Seiti Mizuta
 
Package and distribute your Python code
Package and distribute your Python codePackage and distribute your Python code
Package and distribute your Python codeSanket Saurav
 
S.O.L.I.D. - Павел Кохан, Python Meetup 26.09.2014
S.O.L.I.D. - Павел Кохан, Python Meetup 26.09.2014S.O.L.I.D. - Павел Кохан, Python Meetup 26.09.2014
S.O.L.I.D. - Павел Кохан, Python Meetup 26.09.2014Python Meetup
 
Best Practices for Front-End Django Developers
Best Practices for Front-End Django DevelopersBest Practices for Front-End Django Developers
Best Practices for Front-End Django DevelopersChristine Cheung
 
Como DDD e Strategic Design estão nos ajudando a modernizar um Legado
Como DDD e Strategic Design estão nos ajudando a modernizar um LegadoComo DDD e Strategic Design estão nos ajudando a modernizar um Legado
Como DDD e Strategic Design estão nos ajudando a modernizar um LegadoLuiz Costa
 
Hexagonal Design in Django
Hexagonal Design in DjangoHexagonal Design in Django
Hexagonal Design in Djangomvschaik
 

En vedette (20)

Multi Tenancy With Python and Django
Multi Tenancy With Python and DjangoMulti Tenancy With Python and Django
Multi Tenancy With Python and Django
 
Postgres performance for humans
Postgres performance for humansPostgres performance for humans
Postgres performance for humans
 
Developing Software As A Service App with Python & Django
Developing Software As A Service App with Python & DjangoDeveloping Software As A Service App with Python & Django
Developing Software As A Service App with Python & Django
 
SaaSy maps - using django-tenants and geodjango to provide web-gis software-a...
SaaSy maps - using django-tenants and geodjango to provide web-gis software-a...SaaSy maps - using django-tenants and geodjango to provide web-gis software-a...
SaaSy maps - using django-tenants and geodjango to provide web-gis software-a...
 
Django multi-tier
Django multi-tierDjango multi-tier
Django multi-tier
 
Django Multi-DB in Anger
Django Multi-DB in AngerDjango Multi-DB in Anger
Django Multi-DB in Anger
 
ZCA: A component architecture for Python
ZCA: A component architecture for PythonZCA: A component architecture for Python
ZCA: A component architecture for Python
 
LCNUG 2015 - what's new for agile teams in TFS 2015
LCNUG 2015 -  what's new for agile teams in TFS 2015LCNUG 2015 -  what's new for agile teams in TFS 2015
LCNUG 2015 - what's new for agile teams in TFS 2015
 
Dev/Test Scenarios in the DevOps World
Dev/Test Scenarios in the DevOps WorldDev/Test Scenarios in the DevOps World
Dev/Test Scenarios in the DevOps World
 
Intro django
Intro djangoIntro django
Intro django
 
Why Django
Why DjangoWhy Django
Why Django
 
Global Windows Azure Bootcamp : Samuel et Emilien Pécoul, Florent Pelet Legac...
Global Windows Azure Bootcamp : Samuel et Emilien Pécoul, Florent Pelet Legac...Global Windows Azure Bootcamp : Samuel et Emilien Pécoul, Florent Pelet Legac...
Global Windows Azure Bootcamp : Samuel et Emilien Pécoul, Florent Pelet Legac...
 
Driven Development - Closing the Loop on Scrum
Driven Development - Closing the Loop on ScrumDriven Development - Closing the Loop on Scrum
Driven Development - Closing the Loop on Scrum
 
Sofware Fora de Séria 2016 - Implementando realtime no frontend
Sofware Fora de Séria 2016 - Implementando realtime no frontendSofware Fora de Séria 2016 - Implementando realtime no frontend
Sofware Fora de Séria 2016 - Implementando realtime no frontend
 
Package and distribute your Python code
Package and distribute your Python codePackage and distribute your Python code
Package and distribute your Python code
 
S.O.L.I.D. - Павел Кохан, Python Meetup 26.09.2014
S.O.L.I.D. - Павел Кохан, Python Meetup 26.09.2014S.O.L.I.D. - Павел Кохан, Python Meetup 26.09.2014
S.O.L.I.D. - Павел Кохан, Python Meetup 26.09.2014
 
Best Practices for Front-End Django Developers
Best Practices for Front-End Django DevelopersBest Practices for Front-End Django Developers
Best Practices for Front-End Django Developers
 
Como DDD e Strategic Design estão nos ajudando a modernizar um Legado
Como DDD e Strategic Design estão nos ajudando a modernizar um LegadoComo DDD e Strategic Design estão nos ajudando a modernizar um Legado
Como DDD e Strategic Design estão nos ajudando a modernizar um Legado
 
Organise a Code Dojo!
Organise a Code Dojo!Organise a Code Dojo!
Organise a Code Dojo!
 
Hexagonal Design in Django
Hexagonal Design in DjangoHexagonal Design in Django
Hexagonal Design in Django
 

Similaire à Moving from Django Apps to Services

Tools for Agility
Tools for AgilityTools for Agility
Tools for AgilityCory Foy
 
Benvenuti nella “API Economy”
Benvenuti nella “API Economy”Benvenuti nella “API Economy”
Benvenuti nella “API Economy”Codemotion
 
Modernizing i5 Applications
Modernizing i5 ApplicationsModernizing i5 Applications
Modernizing i5 ApplicationsZendCon
 
TechMeetups Mobile App Workshop for Beginners
TechMeetups Mobile App Workshop for Beginners TechMeetups Mobile App Workshop for Beginners
TechMeetups Mobile App Workshop for Beginners TechMeetups
 
Web Performance Culture and Tools at Etsy
Web Performance Culture and Tools at EtsyWeb Performance Culture and Tools at Etsy
Web Performance Culture and Tools at EtsyMike Brittain
 
De jornais impressos a plataformas online de conteúdo (APIs)
De jornais impressos a plataformas online de conteúdo (APIs)De jornais impressos a plataformas online de conteúdo (APIs)
De jornais impressos a plataformas online de conteúdo (APIs)Pedro Valente
 
Lectura 2.4 is your api naked - 10 roadmap considerations
Lectura 2.4   is your api naked - 10 roadmap considerationsLectura 2.4   is your api naked - 10 roadmap considerations
Lectura 2.4 is your api naked - 10 roadmap considerationsMatias Menendez
 
Building Rich, Interactive E-commerce Applications Using ASP.NET and Silverlight
Building Rich, Interactive E-commerce Applications Using ASP.NET and SilverlightBuilding Rich, Interactive E-commerce Applications Using ASP.NET and Silverlight
Building Rich, Interactive E-commerce Applications Using ASP.NET and Silverlightgoodfriday
 
Notes (2012-06-08)
Notes (2012-06-08)Notes (2012-06-08)
Notes (2012-06-08)Chris Pitt
 
apidays LIVE Australia 2020 - Federating API Development at Australia’s large...
apidays LIVE Australia 2020 - Federating API Development at Australia’s large...apidays LIVE Australia 2020 - Federating API Development at Australia’s large...
apidays LIVE Australia 2020 - Federating API Development at Australia’s large...apidays
 
Cake php concept to deployment
Cake php concept to deploymentCake php concept to deployment
Cake php concept to deploymentilsanbao
 
Cake php 1 3 concept to deployment presentation
Cake php 1 3 concept to deployment presentationCake php 1 3 concept to deployment presentation
Cake php 1 3 concept to deployment presentationlaminbarrow
 
International Content: Next Level Considerations
International Content: Next Level ConsiderationsInternational Content: Next Level Considerations
International Content: Next Level ConsiderationsZeph Snapp
 
Behaviour driven infrastructure
Behaviour driven infrastructureBehaviour driven infrastructure
Behaviour driven infrastructureLindsay Holmwood
 
APIs for your Business + Stages of the API Lifecycle
APIs for your Business + Stages of the API LifecycleAPIs for your Business + Stages of the API Lifecycle
APIs for your Business + Stages of the API Lifecycle3scale
 
Business Analytics with R
Business Analytics with R Business Analytics with R
Business Analytics with R Edureka!
 
Writing Software not Code with Cucumber
Writing Software not Code with CucumberWriting Software not Code with Cucumber
Writing Software not Code with CucumberBen Mabey
 
APIdays Paris 2019 - Adopting Service Mesh by Marco Palladino , Kong
APIdays Paris 2019 - Adopting Service Mesh by Marco Palladino , KongAPIdays Paris 2019 - Adopting Service Mesh by Marco Palladino , Kong
APIdays Paris 2019 - Adopting Service Mesh by Marco Palladino , Kongapidays
 
Web/App Development, Design, and SAAS Services Beginner's Tutorial from A to Z
Web/App Development, Design, and SAAS Services Beginner's Tutorial from A to ZWeb/App Development, Design, and SAAS Services Beginner's Tutorial from A to Z
Web/App Development, Design, and SAAS Services Beginner's Tutorial from A to ZSuperHero Marketing
 

Similaire à Moving from Django Apps to Services (20)

Tools for Agility
Tools for AgilityTools for Agility
Tools for Agility
 
Benvenuti nella “API Economy”
Benvenuti nella “API Economy”Benvenuti nella “API Economy”
Benvenuti nella “API Economy”
 
Modernizing i5 Applications
Modernizing i5 ApplicationsModernizing i5 Applications
Modernizing i5 Applications
 
Thinking Small
Thinking SmallThinking Small
Thinking Small
 
TechMeetups Mobile App Workshop for Beginners
TechMeetups Mobile App Workshop for Beginners TechMeetups Mobile App Workshop for Beginners
TechMeetups Mobile App Workshop for Beginners
 
Web Performance Culture and Tools at Etsy
Web Performance Culture and Tools at EtsyWeb Performance Culture and Tools at Etsy
Web Performance Culture and Tools at Etsy
 
De jornais impressos a plataformas online de conteúdo (APIs)
De jornais impressos a plataformas online de conteúdo (APIs)De jornais impressos a plataformas online de conteúdo (APIs)
De jornais impressos a plataformas online de conteúdo (APIs)
 
Lectura 2.4 is your api naked - 10 roadmap considerations
Lectura 2.4   is your api naked - 10 roadmap considerationsLectura 2.4   is your api naked - 10 roadmap considerations
Lectura 2.4 is your api naked - 10 roadmap considerations
 
Building Rich, Interactive E-commerce Applications Using ASP.NET and Silverlight
Building Rich, Interactive E-commerce Applications Using ASP.NET and SilverlightBuilding Rich, Interactive E-commerce Applications Using ASP.NET and Silverlight
Building Rich, Interactive E-commerce Applications Using ASP.NET and Silverlight
 
Notes (2012-06-08)
Notes (2012-06-08)Notes (2012-06-08)
Notes (2012-06-08)
 
apidays LIVE Australia 2020 - Federating API Development at Australia’s large...
apidays LIVE Australia 2020 - Federating API Development at Australia’s large...apidays LIVE Australia 2020 - Federating API Development at Australia’s large...
apidays LIVE Australia 2020 - Federating API Development at Australia’s large...
 
Cake php concept to deployment
Cake php concept to deploymentCake php concept to deployment
Cake php concept to deployment
 
Cake php 1 3 concept to deployment presentation
Cake php 1 3 concept to deployment presentationCake php 1 3 concept to deployment presentation
Cake php 1 3 concept to deployment presentation
 
International Content: Next Level Considerations
International Content: Next Level ConsiderationsInternational Content: Next Level Considerations
International Content: Next Level Considerations
 
Behaviour driven infrastructure
Behaviour driven infrastructureBehaviour driven infrastructure
Behaviour driven infrastructure
 
APIs for your Business + Stages of the API Lifecycle
APIs for your Business + Stages of the API LifecycleAPIs for your Business + Stages of the API Lifecycle
APIs for your Business + Stages of the API Lifecycle
 
Business Analytics with R
Business Analytics with R Business Analytics with R
Business Analytics with R
 
Writing Software not Code with Cucumber
Writing Software not Code with CucumberWriting Software not Code with Cucumber
Writing Software not Code with Cucumber
 
APIdays Paris 2019 - Adopting Service Mesh by Marco Palladino , Kong
APIdays Paris 2019 - Adopting Service Mesh by Marco Palladino , KongAPIdays Paris 2019 - Adopting Service Mesh by Marco Palladino , Kong
APIdays Paris 2019 - Adopting Service Mesh by Marco Palladino , Kong
 
Web/App Development, Design, and SAAS Services Beginner's Tutorial from A to Z
Web/App Development, Design, and SAAS Services Beginner's Tutorial from A to ZWeb/App Development, Design, and SAAS Services Beginner's Tutorial from A to Z
Web/App Development, Design, and SAAS Services Beginner's Tutorial from A to Z
 

Moving from Django Apps to Services

  • 1. Django Apps to Services
  • 2. Craig Kerstiens @craigkerstiens work at @heroku
  • 3. Django Project A collection of configuration and apps for a particular Website. (per Django Project)
  • 4. Django Project A collection of configuration and apps for a particular Website. App A web application that does something. I.e. Weblog, Poll, Ticket system (per Django Project)
  • 5. Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table
  • 6. Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table
  • 7. Table Table Table Table p Table Table Table p Table A Table Table Table Table Table Table Table Table Table Table Table Table Table
  • 9. Monolithic Monster $ ls mysite models.py views.py forms.py admin.py
  • 10. Monolithic Monster $ ls mysite $ wc -l models.py models.py 2557 models.py views.py $ wc -l view.spy forms.py 14241 views.py admin.py
  • 11. Monolithic Monster $ ls mysite $ wc -l models.py models.py 2557 models.py views.py $ wc -l view.spy forms.py 14241 views.py admin.py http://www.slideshare.net/jacobian/the-best-and-worst-of-django
  • 14. Within Django Project App App App
  • 15. Within Django Project Tickets App FAQ App FaqCreator App
  • 16. Within Django cd myproject && find . manage.py Project requirements.txt settings.py urls.py ./faq/admin.py ./faq/forms.py Tickets App ./faq/models.py ./faq/urls.py ./faq/views.py ./faqcreator/admin.py FAQ App ./faqcreator/forms.py ./faqcreator/models.py ./faqcreator/urls.py ./faqcreator/views.py ./tickets/admin.py FaqCreator App ./tickets/forms.py ./tickets/models.py ./tickets/urls.py ./tickets/views.py
  • 18. cd myproject && find . Reusability
  • 19. cd myproject && find . Reusability manage.py requirements.txt settings.py urls.py ./faq/admin.py ./faq/forms.py ./faq/models.py ./faq/urls.py ./faq/views.py ./faqcreator/admin.py ./faqcreator/forms.py ./faqcreator/models.py ./faqcreator/urls.py ./faqcreator/views.py ./tickets/admin.py ./tickets/forms.py ./tickets/models.py ./tickets/urls.py ./tickets/views.py
  • 20. cd myproject && find . Reusability cd myproject && find . manage.py requirements.txt manage.py settings.py requirements.txt urls.py settings.py ./faq/admin.py urls.py --> ./faq/forms.py ./faq/models.py cat myproject/requirements.txt ./faq/urls.py ./faq/views.py faq==0.1 ./faqcreator/admin.py faqcreator==0.1 ./faqcreator/forms.py tickets==0.1 ./faqcreator/models.py ./faqcreator/urls.py ./faqcreator/views.py ./tickets/admin.py ./tickets/forms.py ./tickets/models.py ./tickets/urls.py ./tickets/views.py
  • 21.
  • 22. REUSABILITY means faster features due to DRY (Don’t Repeat Yourself )
  • 23. REUSABILITY means faster features due to DRY (Don’t Repeat Yourself ) REUSABILITY does not always mean SCALABILITY or MAINTAINABILITY
  • 24. Django Project A collection of configuration and apps for a particular Website. App A web application that does something. I.e. Weblog, Poll, Ticket system (per Django Project)
  • 25. Django Project A collection of configuration and apps for a particular Website. App A web application that does something. I.e. Weblog, Poll, Ticket system Service Method of communication over the web. Web APIs allow combination of multiple services
  • 26.
  • 27. Tech imitate Teams Project Company Tickets App Support FAQ App Knowledge Base FaqCreator App
  • 28. Teams Support Knowledge Base
  • 29. Teams Grow App Support App Knowledge Base
  • 30. Teams Grow App Support App Knowledge Base Billing
  • 31. Teams Grow App Support Marketing App Knowledge Base Billing
  • 32. Teams Grow App Support Marketing API App Knowledge Base Analytics Front End Billing Mobile Social
  • 33. Apps Grow App Support Marketing API p s App A p Knowledge Base Analytics Front End 3 App Billing Mobile Social
  • 34. Apps Grow App Support p App s Marketing App API A p 9 App Knowledge Base App Analytics App Front End App Billing App Mobile App Social
  • 35. Apps Grow Support p s Marketing API Ap se Knowledge Base 9 deb a Analytics Front End Billing C o Mobile Social 1
  • 36. SOA To the Rescue
  • 37. SOA To the Rescue
  • 38. SOA To the Rescue Photo by Paul Downey (psd on flickr)
  • 40. Service Defined contract for communicating $ curl -O $FAQ_API/create/ -X “question=my question source=123”
  • 42. In Python data = { ‘question’: “my question”, ‘source’: 123 } requests.POST(os.environ[‘FAQ_API’] + ‘/ create/’, data=data)
  • 44. More than just API www.google.com
  • 45. More than just API www.google.com mail.google.com
  • 46. More than just API www.google.com mail.google.com calendar.google.com
  • 47. More than just API www.google.com mail.google.com calendar.google.com ..............google.com
  • 53. Types of Services site subdomain API - no auth required - API auth required
  • 54. Types of Services site subdomain API - no auth required - API auth required - user auth required
  • 55. Where to Start App Support App Marketing App API App Knowledge Base App Analytics App Front End App Billing App Mobile App Social
  • 56. Where to Start App Support App Marketing API App Knowledge Base Analytics Front End Billing Mobile App Social
  • 57.
  • 58.
  • 59.
  • 61.
  • 62.
  • 63.
  • 65. Within Django cd myproject && find . manage.py Project requirements.txt settings.py urls.py ./faq/admin.py ./faq/forms.py Tickets App ./faq/models.py ./faq/urls.py ./faq/views.py ./faqcreator/admin.py FAQ App ./faqcreator/forms.py ./faqcreator/models.py ./faqcreator/urls.py ./faqcreator/views.py ./tickets/admin.py FaqCreator App ./tickets/forms.py ./tickets/models.py ./tickets/urls.py ./tickets/views.py
  • 66. Apps Depend on Other Apps
  • 67. Apps Depend on Other Apps faq creator
  • 68. Apps Depend on Other Apps faq creator faq app
  • 69. Apps Depend on Other Apps faq creator faq app ticket
  • 70. Apps Depend on Other Apps faq creator faq app ticket faq app
  • 71. Apps Depend on Other Apps faq creator faq app version == 0.1 ticket faq app version == 0.2
  • 72. Apps Depend on Other Apps pip install faq==0.1 pip install faq==0.2 pip freeze faq==0.2
  • 73. Apps Depend on Other Apps faq creator faq app version == 0.1 ticket faq app version == 0.2
  • 75. What’s a service Provider API_HOST= http://127.0.0.1
  • 76. What’s a service Provider API_HOST= http://127.0.0.1 Endpoint /v1/create/
  • 77. What’s a service Provider API_HOST= http://127.0.0.1 Endpoint /v1/create/ Contract { ‘question’: ‘foo bar’, ‘source’: 123 }
  • 78. App
  • 79. App URLs Views Models
  • 80. App URLs Views Models Service Provider Endpoint Contract
  • 81. A SERVICE means REUSABILITY and enables SCALABILITY and MAINTAINABILITY
  • 83. Where to start 1. If you’re monolithic, break up the apps first
  • 84. Where to start 1. If you’re monolithic, break up the apps first 2. Port something that doesn’t require user
  • 85. Where to start 1. If you’re monolithic, break up the apps first 2. Port something that doesn’t require user 3. Port where you have many dependencies
  • 86. Porting an App models.py class Faq(models.Model): title = models.CharField(max_length=100) source = models.IntegerField(blank=True, null=True) description = models.TextField() solution = models.TextField() def __unicode__(self): return self.title
  • 87. Porting an App faqcreator/views.py from faq.models import faq i = Faq(title=‘foo’, description=‘bar’, solution=’la posta’) i.save()
  • 88. Turn it into an API
  • 89. Turn it into an API 1. pip install django-tastypie
  • 90. Turn it into an API 1. pip install django-tastypie 2. add tastypie to INSTALLED_APPS
  • 91. Turn it into an API 1. pip install django-tastypie 2. add tastypie to INSTALLED_APPS 3. define your APIs
  • 92. Create your API from faq/api.py tastypie.resources import ModelResource from faq.models import Faq from django.contrib.auth.models import User from tastypie.authentication import BasicAuthentication, DjangoAuthorization from tastypie.authorization import Authorization class FaqResource(ModelResource): class Meta: queryset = Faq.objects.all() resource_name = 'faq' list_allowed_methods = ['get', 'post'] authentication = BasicAuthentication() authorization = Authorization() def obj_create(self, bundle, request=None, **kwargs): return super(FaqResource, self).obj_create(bundle, request, user=request.user) def apply_authorization_limits(self, request, object_list): return object_list.filter(user=request.user)
  • 93. Create your API api.py class FaqResource(ModelResource): class Meta: queryset = Faq.objects.all() resource_name = 'faq' list_allowed_methods = ['get', 'post'] authentication = BasicAuthentication() authorization = Authorization() def obj_create(self, bundle, request=None, **kwargs): return super(FaqResource, self).obj_create( bundle, request, user=request.user) def apply_authorization_limits(self, request, object_list): return object_list.filter(user=request.user)
  • 94. Create your API api.py class FaqResource(ModelResource): class Meta: queryset = Faq.objects.all() resource_name = 'faq' list_allowed_methods = ['get', 'post'] authentication = BasicAuthentication() authorization = Authorization() def obj_create(self, bundle, request=None, **kwargs): return super(FaqResource, self).obj_create( bundle, request, user=request.user) def apply_authorization_limits(self, request, object_list): return object_list.filter(user=request.user)
  • 95. Create your API api.py class FaqResource(ModelResource): class Meta: queryset = Faq.objects.all() resource_name = 'faq' list_allowed_methods = ['get', 'post'] authentication = BasicAuthentication() authorization = Authorization() def obj_create(self, bundle, request=None, **kwargs): return super(FaqResource, self).obj_create( bundle, request, user=request.user) def apply_authorization_limits(self, request, object_list): return object_list.filter(user=request.user)
  • 96. Create your API api.py class FaqResource(ModelResource): class Meta: queryset = Faq.objects.all() resource_name = 'faq' list_allowed_methods = ['get', 'post'] authentication = BasicAuthentication() authorization = Authorization() def obj_create(self, bundle, request=None, **kwargs): return super(FaqResource, self).obj_create( bundle, request, user=request.user) def apply_authorization_limits(self, request, object_list): return object_list.filter(user=request.user)
  • 97. Create your API api.py class FaqResource(ModelResource): class Meta: queryset = Faq.objects.all() resource_name = 'faq' list_allowed_methods = ['get', 'post'] authentication = BasicAuthentication() authorization = Authorization() def obj_create(self, bundle, request=None, **kwargs): return super(FaqResource, self).obj_create( bundle, request, user=request.user) def apply_authorization_limits(self, request, object_list): return object_list.filter(user=request.user)
  • 98. Create your API api.py class FaqResource(ModelResource): class Meta: queryset = Faq.objects.all() resource_name = 'faq' list_allowed_methods = ['get', 'post'] authentication = BasicAuthentication() authorization = Authorization() def obj_create(self, bundle, request=None, **kwargs): return super(FaqResource, self).obj_create( bundle, request, user=request.user) def apply_authorization_limits(self, request, object_list): return object_list.filter(user=request.user)
  • 99. Create your API urls.py from faq.api import FaqResource from tastypie.api import Api v1_api = Api(api_name='v1') v1_api.register(FaqResource()) urlpatterns = patterns('', url(r'^api/', include(v1_api.urls)), )
  • 100. Use your API curl -H "Content-Type: application/json" --user admin:testing -X POST --data '{"title": "New FAQ", "source": "1", "description": "foo", "solution": "bar"}' http://127.0.0.1:8000/api/v1/faq/
  • 101. Use it in Python
  • 102. Use it in Python data = { 'title': 'New FAQ', 'source': '1', 'description': 'foo', 'solution': 'bar' } r = requests.post(os.environ[‘FAQ_API’] + "api/v1/faq/", data=data, auth=('admin', 'testing'))
  • 104. Version Bump data = { 'title': 'New FAQ', 'source': '1', 'description': 'foo', 'solution': 'bar', 'related': ['123', '456'] } r = requests.post(os.environ[‘FAQ_API’] + "api/v2/faq/", data=data, auth=('admin', 'testing'))
  • 106. Version Bump data = { 'title': 'New FAQ', 'source': '1', 'description': 'foo', 'solution': 'bar', 'related': ['123', '456'] } r = requests.post(os.environ[‘FAQ_API’] + "api/v2/faq/", data=data, auth=('admin', 'testing'))
  • 108. In our Application faq_creator/views.py r = requests.post(os.environ[‘FAQ_API’] + "api/v2/faq/", data=data, auth=('admin', 'testing')) ticket/views.py r = requests.post(os.environ[‘FAQ_API’] + "api/v1/faq/", data=data, auth=('admin', 'testing'))
  • 109. cd myproject && find . Reusability cd myproject && find . manage.py requirements.txt manage.py settings.py requirements.txt urls.py settings.py ./faq/admin.py urls.py --> ./faq/forms.py ./faq/models.py cat myproject/requirements.txt ./faq/urls.py ./faq/views.py faq==0.1 ./faqcreator/admin.py faqcreator==0.1 ./faqcreator/forms.py tickets==0.1 ./faqcreator/models.py ./faqcreator/urls.py ./faqcreator/views.py ./tickets/admin.py ./tickets/forms.py ./tickets/models.py ./tickets/urls.py ./tickets/views.py
  • 110. Maintainability/Scalability/Agility cd myproject && find . ls projects manage.py faq-service requirements.txt myproject settings.py cd faq-service && find . urls.py manage.py requirements.txt cat myproject/requirements.txt faq==0.1 --> settings.py urls.py cd myproject && find . faqcreator==0.1 tickets==0.1 manage.py requirements.txt settings.py urls.py cat myproject/requirements.txt faqcreator==0.1 tickets==0.1
  • 112. Maintainability/Scalability/Agility Faq Project - Its own Django project - 1 Django app - Own database - Own deployment
  • 113. Maintainability/Scalability/Agility My Project Faq Project - Contained Django Project - Its own Django project - 2 Django apps - 1 Django app - Own database - Own database - Own deployment - Own deployment
  • 115. Take aways 1. Start non-critical (Cheat) 2. Create services where theres app reuse 3. Create services where theres pain 4. Start small
  • 116. Others
  • 117. Others 1. Expect APIs to fail 2. Flask is great for APIs 3. Make it easy to setup/test