1 of 11

While you’re waiting…

Check

  1. python --version
    1. If not Python 3, download from https://www.python.org/downloads/
  2. pip install Flask
    • MUST BE capital F

NEXT

git clone https://github.com/thomasdriscoll/workshops-open-source-illinois.git

  • Open workshop2 folder in favorite text editor
  • This Powerpoint is on line 2 of server.py

2 of 11

Flask + API Workshop

By Thomas Driscoll and Roshini!

3 of 11

What’s a REST API?

  • REST = Representational State Transfer
  • A server that performs functions on request
    • What’s a server?
    • What kind of functions?
    • What do I mean by request?

4 of 11

ReST API Operations

5 of 11

URL Routing Example

https://calendar.google.com/calendar/r/week

Go to Google calendar and follow along!

Challenge: How would you change your view to be day? month?

6 of 11

What is Flask?

  • A Python microframework
  • Most frameworks have
    • Accounts, authentication, authorization, roles, etc.
    • Database abstraction via an object-relational mapping.
    • Input validation and input sanitation.
    • Web template engine.
  • Python CAN DO ALL OF THESE
    • Just use libraries
    • I’ll actually use all these in this workshop hehehe
  • https://flask.palletsprojects.com/en/1.1.x/

7 of 11

File Structure of a Flask project

/myproject

/server.py

/templates

/index.html

/static

/helper.js

8 of 11

Templating

  • Shoutout to my HTML workshop attendees <3
  • Jinja2 templating
  • Why? D.R.Y.
  • How to think of it?
    • Creating a base form
    • Other files fill in the “insert non-generic content here” parts
  • Specify url and build your page!

9 of 11

REST Operations in Flask

10 of 11

… But for real

11 of 11

What we will be doing today

  1. Walk through basic GET/POST together
  2. Fill out remaining operations independently
  3. Work together on PUT from HTML to server
  4. Render your own page to interesting things!!!