MIP BE

Ingredients

  • Flask
  • Flask-RESTful
  • pip
  • virtualenv
  • Django
  • Elasticsearch
  • Redis

Flask

Flask is a microframework for Python based on Werkzeug, Jinja 2 and good intentions. And before you ask: It's BSD licensed!

http://flask.pocoo.org/

Flask is Fun

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run()

And Easy to Setup

$ pip install Flask
$ python hello.py
 * Running on http://localhost:5000/

What’s in the Box?

What is REST?

REST stands for Representational State Transfer.

It relies on a stateless, client-server, cacheable communications protocol

-- and in virtually all cases, the HTTP protocol is used.

REST is an architecture style for designing networked applications..

The idea is that, rather than using complex mechanisms such as CORBA, RPC or SOAP to connect between machines, simple HTTP is used to make calls between machines.

In many ways, the World Wide Web itself, based on HTTP, can be viewed as a REST-based architecture.
http://rest.elkstein.org/
stackoverflow -> http://bit.ly/RFLMof

Flask-RESTful

Flask-RESTful is an extension for Flask that adds support for quickly building REST APIs. It is a lightweight abstraction that works with your existing ORM/libraries. Flask-RESTful encourages best practices with minimal setup. If you are familiar with Flask, Flask-RESTful should be easy to pick up.


Installation

pip install flask-restful

Quickstart

from flask import Flask
from flask.ext import restful

app = Flask(__name__)
api = restful.Api(app)

class HelloWorld(restful.Resource):
    def get(self):
        return {'hello': 'world'}

api.add_resource(HelloWorld, '/')

if __name__ == '__main__':
    app.run(debug=True        )

Try it

$ python api.py
 * Running on http://127.0.0.1:5000/
http://flask-restful.readthedocs.org/en/latest/quickstart.html#
Made with Slides.com