Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Let's Learn Flask

Let's Learn Flask

Kickstarting Api development with flask

smit thakkar

January 28, 2017
Tweet

More Decks by smit thakkar

Other Decks in Programming

Transcript

  1. • I work for Lendcypher as a Full Stack Developer.

    • I am author of an open source Flask extension : Flask-NSFW and Flask-ReqParse • Former Technical Co-Founder at Punchit.io. • Technology Stack : Python FLask, AngularJs, Mongodb, SQL, Native ios apps with Swift. • Hackathon Lover • Email : [email protected] • Github : github.com/smitthakkar96 • Facebook : https://www.facebook.com/geekysmit Who Am I?
  2. Agenda • Tools with which we are gonna hack on

    • Why Flask? • Setup • Example Application Demonstration • Let’s build an Application ◦ Hello, Flask! ◦ Rest APIs ◦ Request and Response ◦ on mechanism ◦ Let’s build a todo apps • What’s next?
  3. Setup • Python Interpreter ◦ Python 3.5 or Python 3.4

    ◦ Python 2.7 + virtualenv • Pip install flask
  4. Why Flask? • Small, lightweight, straightforward. • Adapts easily to

    the way of your thinking. • Plays well with third party packages. • Lot many open source Flask-Extensions (Even easy to create one) • Largest community
  5. Some Known FLask Extensions • Flask-Admin • Flask-SQlAlchemy • Flask-NSFW

    • Flask-MongoAlchemy • Flask-CORS • Flask-WTF • Flask-Cache • And much more..
  6. Hello Flask! • Create a project directory • Create a

    virtual environment • Install Flask
  7. REST API REST is a software design pattern typically used

    for web applications. In layman's terms this means that it is a commonly used idea used in many different projects. It stands for REpresentational State Transfer. The basic idea of REST is treating objects on the server-side (as in rows in a database table) as resources than can be created or destroyed. The most basic way of thinking about REST is as a way of formatting the URL's of your web applications. For example, if your resource was called "posts", then: /posts Would be how a user would access ALL the posts, for displaying. /posts/:id Would be how a user would access and view an individual post, retrieved based on their unique id. /posts/new Would be how you would display a form for creating a new post. Sending a POST request to /users would be how you would actually create a new post on the database level. Sending a PUT request to /users/:id would be how you would update the attributes of a given post, again identified by a unique id.
  8. Response codes • 200 - ok • 400 - Bad

    Request • 401 - unauthorized • 403 - forbidden • 404 - not found • 500 - internal server error
  9. SQLite Supported data types Integer an integer String (size) a

    string with a maximum length Text some longer unicode text DateTime date and time expressed as Python datetime object. Float stores floating point values Boolean stores a boolean value PickleType stores a pickled Python object Large Binary stores large arbitrary binary data