taking you api to the next level django rest framework
play

Taking you API to the next level Django Rest Framework $whoami - PowerPoint PPT Presentation

Taking you API to the next level Django Rest Framework $whoami Carlos Martnez Backend Developer en twitter @carlosmart626 github carlosmart626 https://carlosmart.co $whoami Colombia @carlosmart626 $whoami @carlosmart626 5


  1. Taking you API to the next level

  2. Django Rest Framework

  3. $whoami Carlos Martínez  Backend Developer en twitter @carlosmart626 github carlosmart626 https://carlosmart.co

  4. $whoami Colombia  @carlosmart626

  5. $whoami @carlosmart626

  6. 5 Minute API

  7. Ticket Store Users Events Promotors Tickets @carlosmart626

  8. Display different data based on context Getting better performance Filtering information Permissions How to render results in different formats? @carlosmart626

  9. Reuse Serializers

  10. How to reuse your serializers to show different representations? Create multiple ModelSerializer with different selected fields @carlosmart626

  11. How to reuse your serializers to show different representations? DynamicSerializers! @carlosmart626

  12. Dynamic Serializers Use DynamicSerializer instead ModelSerializer @carlosmart626

  13. Dynamic Serializers Use DynamicSerializer instead ModelSerializer @carlosmart626

  14. Dynamic Serializers @carlosmart626

  15. Dynamic Serializers Now you can reuse the serializer easier @carlosmart626

  16. Getting better performance @carlosmart626

  17. Prefetch Keep in mind the number of queries @carlosmart626

  18. Prefetch Select Related Follow foreign key relationships by getting a single but more complex query @carlosmart626

  19. Prefetch Select Related Follow foreign key relationships by getting a single but more complex query django/querysets/#select-related @carlosmart626

  20. Prefetch Select Related Follow foreign key relationships by getting a single but more complex query @carlosmart626

  21. Prefetch Query @carlosmart626

  22. Prefetch Query @carlosmart626

  23. Prefetch Prefetch Related Great to many-to-many and many-to-one @carlosmart626

  24. Prefetch Prefetch Related Similar to ‘select_related’ creates a more queries executed to get the related data @carlosmart626

  25. Prefetch Prefetch Related Similar to ‘select_related’ creates a more queries executed to get the related data @carlosmart626

  26. Prefetch Prefetch Object This object can be used to customize the ‘prefetch_related’ operations django/querysets/#prefetch-objects @carlosmart626

  27. Prefetch Prefetch Object This object can be used to customize the ‘prefetch_related’ operations django/querysets/#prefetch-objects @carlosmart626

  28. Filtering

  29. django-url-filter Let’s filter your endpoints in a better way @carlosmart626

  30. django-url-filter Add filter_backends and select your filter fields @carlosmart626

  31. django-url-filter Add filter_backends and select your filter fields @carlosmart626

  32. django-url-filter @carlosmart626

  33. django-url-filter ModelFilterSet @carlosmart626

  34. Cache @carlosmart626

  35. Cache View example Django Cache in DRF ModelViewSets @carlosmart626

  36. Cache View example Django Cache in DRF ModelViewSets @carlosmart626

  37. Cache View example Django Cache in DRF ModelViewSets @carlosmart626

  38. Cache Key invalidation DON’T FORGET TO INVALIDATE CACHE @carlosmart626

  39. django-cacheops Cacheops let’s you cache the ORM @carlosmart626

  40. django-cacheops Cacheops can work using redis @carlosmart626

  41. django-cacheops Cacheops common configurations Default time out Apps/Models to cache with operations and time settings @carlosmart626

  42. django-cacheops Cacheops common configurations Default time out Apps/Models to cache with operations and time settings @carlosmart626

  43. django-cacheops Cacheops provides different ways to cache ORM operations It’s automatic! But, you can define a queryset and append cache() at the end to cache the ORM results. https://github.com/Suor/django-cacheops @carlosmart626

  44. django-cacheops Cacheops provides different ways to cache ORM operations It’s automatic! But, you can define a queryset and append cache() at the end to cache the ORM results. https://github.com/Suor/django-cacheops @carlosmart626

  45. Permissions

  46. Permissions DRYPermissions You can define global, object and action permissions in each one of your models. @carlosmart626

  47. DRYPermissions @carlosmart626

  48. DRYPermissions Using DRYPermission in a ViewSet Add to permission_classes DRYPermissions @carlosmart626

  49. DRYPermissions Using DRYPermission in a ViewSet Add to permission_classes DRYPermissions @carlosmart626

  50. DRYPermissions Global Permissions You have access to the request so you can get information about the user @carlosmart626

  51. DRYPermissions Object Permissions You can define object permissions and you get both request and the object to make validations @carlosmart626

  52. DRYPermissions Field/Action Permissions You can define logic to access to fields and actions within a model viewset @carlosmart626

  53. DRYPermissions Custom permission class @carlosmart626

  54. DRYPermissions Custom permission class @carlosmart626

  55. DRYPermissions Custom permission class @carlosmart626

  56. DRYPermissions DRYPermission on APIView Outside a Viewset you need to add to the serializer a context https://github.com/dbkaplan/dry-rest-permissions @carlosmart626

  57. DRYPermissions DRYPermission on APIView Outside a Viewset you need to add to the serializer a context https://github.com/dbkaplan/dry-rest-permissions @carlosmart626

  58. Rederers

  59. XLSXRenderer Drf-renderer-xlsx This package let you export excel files directly from your api instead to get a son you can get a xlsx file with all the filters you already define at the URL @carlosmart626

  60. XLSXRenderer It’s very simple to use @carlosmart626

  61. XLSXRenderer It’s very simple to use @carlosmart626

  62. Code https://github.com/CarlosMart626/ djangocon-2019

  63. Demo 爛

  64. Thank you @carlosmart626

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend