Slide 1

Slide 1 text

RESTful Microservices with Python Antonio Ognio Systems Architect at Red Científica Peruana L I G H T N I N G :. T A L K S:.

Slide 2

Slide 2 text

What is REST anyway?

Slide 3

Slide 3 text

What is a microservice architecture?

Slide 4

Slide 4 text

Why is it a good idea to build this with Python?

Slide 5

Slide 5 text

REST

Slide 6

Slide 6 text

REST (REpresentational State Transfer)

Slide 7

Slide 7 text

REST A way of taking full advantage of the existing web-related protocols and software in order to query and manipulate objects remotely.

Slide 8

Slide 8 text

REST A way of taking full advantage of the existing web-related protocols and software in order to query and manipulate objects remotely.

Slide 9

Slide 9 text

REST ✓ Was reverse-engineered by Roy Fielding for this PhD thesis from the existing web technologies after they were created (2000). Requires you to use provide links to your resources ✓ so your APIs are browseable. Requires you to respect to uniform interface of ✓ HTTP and use each of the verbs without violating their own semantics.

Slide 10

Slide 10 text

REST HTTP Verb CRUD Action GET Read POST Update PUT Create DELETE Delete Isn't REST just a mapping of verbs to.. ?

Slide 11

Slide 11 text

REST HTTP Verb CRUD Action GET Read POST Update PUT Create DELETE Delete Isn't REST just a mapping of verbs to.. ? WRONG!!!

Slide 12

Slide 12 text

Some things you should be doing... ✓ Returning many different status codes not just 200 or 404: Accepted (201) Created (202) No Content (204) Moved Permanently (301) See Other (303) Bad Request (400) Unauthorized (401) Forbidden (403) Method Not Allowed (405) Not Acceptable (406) Conflict (409) Gone (410) Internal Server Error (500) etc.

Slide 13

Slide 13 text

Some things you should be doing... ✓ Making sure one “thing” or “entity” in your domain problem have one and JUST ONE URI associated with it. Providing a “home document” at the root of your service linking to ✓ the main resources available. Using URI templates with named parameters so client code does not ✓ have to hard code URIs. Providing paginated results including hyperlinks to the next, prev, ✓ first and last pages. Returning 200 and not 404 when a search yields no results. ✓ Returning 400 if an input validation fails but a 409 if the data is OK ✓ but there is a business model conflict in the requested action.

Slide 14

Slide 14 text

Master your HTTP codes httpstatus.es Point your browser to for a friendly refresher on available status codes and their actual meanings... Point your browser to

Slide 15

Slide 15 text

Learn more about REST (1) Roy Fielding's PhD dissertation Grab your own free copy of http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm ...it is surprisingly easy to read and very informative

Slide 16

Slide 16 text

Learn more about REST (2) REST for the REST of us Grab your own free copy of http://vimeo.com/82725804 ...a talk at gave at a conference in Chile last year https://speakerdeck.com/gnrfan/rest-for-the-rest-of-us

Slide 17

Slide 17 text

Books on REST I recommend...

Slide 18

Slide 18 text

Microservices

Slide 19

Slide 19 text

Microservice Architecture Building a larger system or service by piecing together smaller services that are usually highly reusable, self-contained, conceptually simple and easy to maintain.

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

Advantages of Microservices ✓ Once you define a public API and others start using it you can change the implementation as you which without breaking things. Each service is so small that one engineer can fully understand it and ✓ make a much better job of maintaining it. You are no longer limited to using an specific language, version or ✓ database for your whole system: use what is best for the job! Upgrading the system one micro-service at a time is much easier ✓ than upgrading a monolithic system. Prototype a microservice in a language you're comfortable with and ✓ re-implement it in any other as needed if that helps for speed or reliability reasons.

Slide 25

Slide 25 text

Learn more about Microservices (1) Martin Fowler's article on Microservices Grab your own free copy of http://martinfowler.com/articles/microservices.html ..it is short but comprehensive and useful in general

Slide 26

Slide 26 text

Learn more about Microservices (2) µCon: The Microservices Conference Attend https://skillsmatter.com/conferences/6312-mucon ..27th and 28th of November 2014, London, UK.

Slide 27

Slide 27 text

Why is it a good idea to build microservices with ?

Slide 28

Slide 28 text

Why Python? (for Microservices) ✓ The most important thing is to get the API right so prototyping quickly and easily is key and Python is great for that. There are good microframeworks available for Python, most notably ✓ Flask, you might not need a full-fledged Django installation. This is a great opportunity to build production code in Python 3. No ✓ more excuses!!! Chance to build asynchronous services using Tornado or Twisted. ✓ Re-implement using PyPy, Cython, Golang, Java, C++, Clojure, etc as ✓ needed if you require more speed or efficiency. You can build a Python web service frontend to many microservices ✓ in legacy languages like PHP, ASP, etc.

Slide 29

Slide 29 text

Useful Python Packages ✓ requests uritemplate ✓ rfc3339 ✓ Tornado ✓ hal-json ✓ halogen ✓ collection-json ✓ negotiator ✓ Flask-Restless ✓ tastypie ✓ djangorestframework ✓ https://github.com/gnrfan/django-restful ✓

Slide 30

Slide 30 text

RESTful Microservices with Python Antonio Ognio Systems Architect at Red Científica Peruana L I G H T N I N G :. T A L K S:.