REST API en Python

REST API

CRUD

Manejo de errores

{
   "status": 401,
   "error_code": 2005,
   "error_message": "Authentication token has expired"
}

Versionado

I) URL: http://api.com/api/v2/dog/1234

II) Parameters: http://api.com/api/dog/1234?v=2.0

III) Header: {Version: 1} http://api.com/api/dog/1234

Microframework para desarrollo de APIs

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello, World!'

WSGI

from wsgiref.simple_server import make_server

def hello(environ, start_response):
    start_response('200 OK',[('Content-type','text/plain')])
    return ['Hola PyAr!']

httpd = make_server('',8000, hello).serve_forever()

Python WSGI HTTP Server for UNIX

# myproject.py

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello, World!'
gunicorn -w 4 -b 127.0.0.1:4000 myproject:app

Heroku + mongo

+

Pruebas

DEMO

¿Preguntas?

Python REST

By Gabriel Fusca

Python REST

  • 352