Slide 1

Slide 1 text

Django API & SDK LEANO Pablo @pablo_amnesiac

Slide 2

Slide 2 text

● Django Rest Framework ● Swagger Specification ● Django Rest Swagger ● Apimatic.io ● Live Demo ● Tips and Advices ● Questions

Slide 3

Slide 3 text

Django REST Framework (DRF) “Django REST framework is a powerful and flexible toolkit for building Web APIs.” A collection of generic classes + Authentication (tokens, sessions, oauth, etc) + Serializers / Renders + Some useful tools (tests, throttling, etc.)

Slide 4

Slide 4 text

Django REST Framework (DRF) Save data

Slide 5

Slide 5 text

Django REST Framework (DRF) Get data

Slide 6

Slide 6 text

Swagger Specification “Swagger is a simple yet powerful representation of your RESTful API” ● Not a library, not code, just a JSON file. ● Lots of goodies: ○ Swagger UI to build a documentation reference or a sandbox for users ○ Swagger Editor / Validator ○ Swagger Codegen creates the code for client and server from a swagger file

Slide 7

Slide 7 text

Swagger Specification V 2.0

Slide 8

Slide 8 text

Django Rest Swagger “Django REST Swagger is a library that generates Swagger documentation from your Django Rest Framework API code.” ● The bad news: generates a Swagger v 1.0 and not Swagger 2.0 ● The good news: In Botify we’ve forked repo and changed a lot the code to produce a Swagger 2.0 ● The bad news: The code is too specific (and dirty) that it won’t probably fit your needs. ● The good news: You can fork Django Rest Swagger Too!!!

Slide 9

Slide 9 text

Apimatic.io “Generate high-quality SDKs for your RESTful APIs with our customizable codegen engine.” ● Long story short: takes your swagger file and generates a SDK ● Like Swagger codegen ● Saas

Slide 10

Slide 10 text

Live Demo

Slide 11

Slide 11 text

Tips and Advices

Slide 12

Slide 12 text

Swagger can’t describe everything [ ["John", "[email protected]", true, 1, 9.23, false, ["voice", "guitar"]], ["Paul", "[email protected]", false, 2, 7.23, false, ["voice", "bass"]] ["Ringo", "[email protected]", true, 3, 1.23, false, ["drums"]] ... ]

Slide 13

Slide 13 text

Swagger can’t describe everything { "john": { "id": 1, "email": "[email protected]" }, "paul": { "id": 2, "email": "[email protected]" }, "ringo": { "id": 3, "email": "[email protected]" }, ... }

Slide 14

Slide 14 text

CBV vs FBV, the old debate ● Don’t use FBV, you can’t introspect them. You might as well write the swagger file manually ● Generic Classes are your friends and they help you DRY

Slide 15

Slide 15 text

To Keep In Mind When Creating an API ● Keep It Clean ○ Use serializers ○ Use Generic classes ○ Skinny Views (AKA Controllers) ● RESTful Is the answer ○ The more you stay REST, the easier to maintain. ○ The more you stay normalized (DB), the less bugs you’ll have.

Slide 16

Slide 16 text

We’re hiring!!! www.botify.com/jobs

Slide 17

Slide 17 text

Questions?