Assignment 1: Internet/Web Basics
- Due Feb 5, 2015 by 11:59pm
- Points 5
- Submitting a file upload
Internet/Web Basics
Assignment 1 IoT Spring 2015
Assigned: Friday, January 30th, 2015
Due: Thursday, February 5th, 2015
Introduction: |
In this assignment you will learn to develop simple distributed applications using Web technologies. After getting familiar with establishing HTTP connections and sending different kinds of HTTP requests, you will create an application that gathers data from a Web service and visualizes it locally. |
|---|---|
Instructions: |
Objectives:Rationale: You will require a solid HTTP foundation and basic knowledge in user interface technologies for the course project. This assignment prepares you for both of these. Prerequisites: The Web services that you will be using throughout this assignment are the BART API as well as a simple test API to a crude online forum. Used Languages: Python, JavaScript (+ jQuery) Deliverables:You should create a zip file containing the Python and JavaScript code created in this assignment. You must make sure that the Python code runs with version 2.7 of the interpreter - remember that your submitted code must work on our machines as well, so use relative paths if you add external libraries to your project, and include these libraries with your zip file. Please use UTF-8 encoding for your documents and avoid special characters. Submit your zip file to Alexander Jones (content line: "IoT Assignment 1 (your-calnet-login)") by February 5 2015, at 11:59pm PST. 1. REST Web Services in Python (3 Points)Your task is to create a Python script that reads data from our test API and pushes data to it. You will see different ways of how this can be done. 1.1 Raw HTTP RequestsOur Web API speaks the HTTP protocol, version 1.1. In this assignment, your first task is to fetch a piece of data from the API using a Hints:
1.2 HTTP Headers and Status CodesFrom the raw HTTP response of the previous exercise, find the values of each of the following parameters. Summarize the meaning of each parameter in a short paragraph (include your answers as comments in your Python code).
The response to your request in the previous exercise should carry the
1.3 HTTP Content NegotiationSo far, you only received HTML responses back from the server. A REST service can, however, offer several representations of the same resource. For instance, many resources also provide JSON representations - JSON is a lightweight version of XML that is often used in Web mashups and REST interfaces because it can directly be translated to JavaScript objects. To obtain a representation of the 1.4 HTTP Requests using the requests LibraryHTTP requests are usually not implemented by hand, but rather using one of many different libraries that take care of the intricacies of the HTTP protocol and connection management. In this task, you should create a method that uses the Python Requests library (you'll need to install that from the given URL) for sending the same HTTP request as you created by hand in task 1.3. This method should also display the JSON representation of the 1.5 Switching Gears: POSTing DataUp until now, you have only used the HTTP GET method to obtain data from the API. For this task, first look up the exact semantics of a few other methods that are specified in the HTTP protocol: POST, PUT, DELETE, HEAD, and OPTIONS. Next, use an HTTP POST request to send a new forum post to the API's { 'author' : 'your-name', 'message' : 'your-message' }
Hints:
1.6 Submission Instructions for this TaskYou should create a single method for each of the tasks 1.1, 1.3, 1.4, and 1.5. Your Python script should call each of these methods in-order. The script should be executable with the command 2 REST Web Services and User Interfaces in JavaScript (2 Points)In this part, you will create a website that uses JavaScript to obtain input from a remote source and display this input. 2.1 Obtaining and parsing XMLIn this task, you should use the BART API. Using its API documentation, find the resource that enables you to access BART's real-time departure estimates. Using this resource, create a simple website that loads the real-time departure estimates from the Downtown Berkeley station and displays a countdown (in steps of seconds) until the next train leaves toward Millbrae. Your website should update itself by re-loading the latest information from the BART API every 30 seconds. Hints:
2.2: The Same-Origin PolicyThe JavaScript same-origin policy aims to prevent cross-site request forgery by limiting how resources on different hosts can interact with each other. Knowing this, why is it possible for your website from task 2.1 to load and display data from the BART API? Include your answer as a comment within the HTML markup of your created website. 2.3 Optional: A jQuery CounterVisualize the remaining time until the next train using the |
Find Rubric