Skip to content

Instantly share code, notes, and snippets.

View tomchristie's full-sized avatar
🌿

Tom Christie tomchristie

🌿
View GitHub Profile
https://github.com/tomchristie/django-rest-framework/issues/1936
https://github.com/tomchristie/django-rest-framework/issues/1891
https://github.com/tomchristie/django-rest-framework/issues/1860
https://github.com/tomchristie/django-rest-framework/issues/1767
https://github.com/tomchristie/django-rest-framework/issues/1649
https://github.com/tomchristie/django-rest-framework/issues/1338
currency_serializer = CurrencySerializer(Currency.objects.all(), many=True)
service_serializer = ServiceModuleMinSerializer(ServiceModule.objects.all(), many=True)
return Response({
'currencies': currency_serializer.data,
'services': service_serializer.data
})
def _get_displayed_page_numbers(current, final):
"""
This utility function determines a list of page numbers to display, based
on the same pagination display style that GitHub use in their issue list pages.
This gives us a nice contextually relevant set of page numbers to display.
For example:
current=14, final=16 -> [1, 2, None, 12, 13, 14, 15, 16]
current=2, final=16 -> [1, 2, 3, 4, 5, None, 15, 16]
* REST framework 0.x - The top branch is the framework. Red branch to the left is docs. Bottom is example projects.
* Big pause - This'd be when my first son was born. Had my hands full.
* You can see when version 2.0 arrives as there's a flurry of activity - the code examples disappear and the docs get loads of work instead.
* During 2.x the tests move out of the package itself, causing another branch off of the center.
* You can tell when version 3.0 arrives, as a whole bunch of blue sponsor images appear in the red docs branch.
* The templated HTML rendering results in three sets of small purple branchs in the main framework, corresponding to vertical, horizontal and inline style templates.
* The big white flower is all the supported languages as we add internationalization to the project.
class InvoiceList(ManyRelatedField):
def __init__(self):
child = InvoiceSerializer()
super(InvoiceList, self).__init__()
def to_representation(self, iterable):
request = self.parent.context['request']
return [
self.child_relation.to_representation(value)
for value in iterable.filter(user=request.user)
@tomchristie
tomchristie / how-to-communicate.md
Created January 22, 2016 11:46
How to communicate

How to communicate

Exploring the fundamentals of how we build networked application interfaces.

What problems are we running into building Web APIs today? How can we best take advantage of Django's upcoming channels work to build realtime systems? What are Django's strengths in the changing API landscape, and how can it stay relevant?

  • REST - Taking a look at the pain points.
  • GraphQL - Why it exists, and what it could mean for the future.
  • Realtime - How we can build realtime interfaces in a more structured way.
  • Hypermedia - Why it hasn't yet lived up to its promises, and how it still might.
class CountryCodeField(serializers.Field):
codes = {'US': 45, 'AU': 12}
def to_internal_value(self, value):
# make sure it is a string
if type(value) is not str:
raise ValidationError('`value` must be a string, you sent type %s' % type(value))
# check length
if len(value) != 2:
doc = Document(
url='/',
title='Notes',
content={
'notes': [
Document(
url='/123/',
title='Note',
content={
'description': 'Write the talk',
response = requests.get('http://api.example.com')
content_type = response.headers.get('content-type')
codec = coreapi.negotiate_decoder(content_type, decoders=decoders)
doc = codec.load(response.content)
.
  • Schema & hypermedia support.
  • Better API documentation options.
  • Client libraries for range of languages.
  • Mature authentication defaults.
  • Faster time-to-production.
  • Performance & monitoring.
  • Debugging tools.
  • Realtime API support & documentation.
  • Highlighting & supporting third party packages.
  • Beta release versions & reducing bus factor.