This document discusses converting Django apps into reusable services. It begins by explaining the typical structure of a Django project with multiple apps. It then discusses some of the challenges with this monolithic structure in terms of reusability, scalability and maintainability.
The document proposes converting apps into reusable services with defined contracts for communication. It provides examples of defining API endpoints and authentication. Converting apps to services allows for improved reusability as apps can be developed and updated independently. It also enables better scalability by removing dependencies between apps.
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)
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
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()
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/
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