The REST server sample code is based on the Flask web framework.
You've installed Flask in lab5, but in this lab, you're going to extend the provided Flask server. If you want a "I just want to make it work" introduction, this tutorial on Flask routes is good. There are official flask tutorials that provide more details.
You're being provided with a starting flask servers in rest-server.py
that provides the basics of the specifics of extracting an image file over REST was devised from an example here to implement the rawimage
API. We also provide the add
method. You'll need to add the jsonimage
and dotproduct
endpoints.
Both of the endpoints you implement can retrieve the JSON arguments using the request.get_json()
method from the Flask request.
We've provided starter code in rest-client.py
that construct a REST request for the rawimage
and add
query. The image query loads a 1.6MB JPG image of the flatirons for processing. The image is from Wikipedia and taken by Jesse Varner. Modified by AzaToth. - Self-made photo.Originally uploaded on 2006-04-19 by Molas. Uploaded edit 2007-12-23 by AzaToth., CC BY-SA 2.5, https://commons.wikimedia.org/w/index.php?curid=3267545. You should use the same image for the jsonimage
endpoint.
You will need to install the base Python3 system as well as the libraries jsonpickle
and Pillow
libraries in addition to the Flask
libraries. The easiest way to do this is using the pip
command. You'll need to install some Python libraries in addition to the flask libraries installed in lab5. This command install the stuff I needed:
sudo pip3 install pillow jsonpickle
You should modify the client and server to implement the add
endpoint and insure that the sample client code receives the correct answer(s). It may be useful to specify a debug
flag that dumps out debug output.
You should then use the client to accept a command-line argument indicating the endpoint to be tested and the number of iterations to test. For example:
python rest-client.py localhost add 1000
would run the add
endpoint 1000 times against the server on the localhost
and then report the time taken divided by the number of queries (1000). This gives you a time-per-query, which should be expressed in milliseconds. The python perf_counter
routine from the time
module makes it easy to conduct such timing tests. We measure multiple queries because each query is fairly short and we want to average over many such queries.