CS 257: Software Design

Getting Started With Flask

Throughout the following discussion, I'm going to assume you're working with Python 3. Most of the instructions work just as well with Python 2, but I won't make any special effort towards Python 2 compatibility.

Whenever I say "yourusername" below, replace it with (can you guess?) your user name.

Web API construction frameworks

Once you have designed a web API, you'll want to write code to implement it, and deploy that code on a publicly accessible server. One of the biggest hassles of API implementation is the of parsing of the URL. For example, if you're implementing queries like "http://wherever.com/authors/Garcia+Marquez", you'll need code to recognize that the caller is requesting the "authors" resource with the author name "Garcia Marquez". Once this information is extracted, you'll probably want to call some sort of get_authors method with the parameter name="Garcia Marquez"--get_authors can then do the job of querying the database and assembling the JSON response to be sent back to the browser/client.

In addition to URL parsing, there are other routine and tedious tasks involved in implementing web services. As a result, many people have devloped "web frameworks"--tools to simplify some of these routine tasks. We will be using one such framework called Flask. Once you have Flask installed and configured, you can focus your attention on the core algorithmic content of your API instead of on repetitive details like URL parsing.

Of course, one of the costs of using extra tools is that you have to install and configure them. That cost is sometimes worth it, and sometimes not, depending on the tool and your needs. The rest of this document is devoted to helping you through the process of setting up and using Flask both on your own computer and on the CS department's computer thacker.mathcs.carleton.edu.

Using Flask on your own computer

Having Flask working on your own machine will help make development of your API more convenient than using the CS department server. Once you have your API working, you'll be able to deploy it to thacker.mathcs.carleton.edu so other people can see your work.

Here's how to get going with Flask on your computer.

Using PostgreSQL on thacker

Using Flask on thacker

Your port

Here's each person's port for using Flask on thacker.

bakerk2 5102 bursonj 5103 celikk 5104 chavezl 5105 chenx2 5106 childv 5107 considinez 5108 crenshawm 5109 cristofaroe 5110 dewans 5111 domogallaj 5112 donahuec2 5113 forbesd 5114 greenm2 5115 greenbergh 5116 hallstromr 5117 hedayatim 5118 javalym 5119 kapelkei 5120 kimj4 5121 kleina3 5122 kleina2 5123 konuka 5124 kuob 5125 lacroixa 5126 liur3 5127 liut2 5128 mawbye 5129 mchughs 5130 neubauers 5131 orvisw 5132 phillipsl 5133 pitkofskyj 5134 richardsw 5135 rosenberge 5136 serranos 5137 shenr 5138 shoemakerc 5139 spinalen 5140 tagoec 5141 taod 5142 tigara 5143 villarrealm 5144 wangs3 5145 wangy2 5146 warrena 5147 wooldridgep 5148 woosnama 5149 jondich 5150