IoT Spring 2015 (CCN 41607 & 41866)
Assignment 1: Internet/Web Basics
Skip To Content
Dashboard
  • Login
  • Dashboard
  • Calendar
  • Inbox
  • History
  • Help
Close
  1. My Dashboard
  2. IoT Spring 2015 (CCN 41607 & 41866)
  3. Assignments
  4. Assignment 1: Internet/Web Basics
Spring 2015
  • Home
  • Assignments
  • Files
  • Syllabus
  • Collaborations
  • Media Gallery
  • Academic Integrity

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 Requests

Our 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 raw HTTP request, i.e. without the use of any external library: Create a method in your Python program that opens a TCP connection and sends an HTTP GET request to obtain the HTML representation of the /posts resource from the API. Your method should then display the API's raw, unparsed response on the screen (i.e. including the returned HTTP headers).

Hints:
  • Use the Python socket module to create a basic TCP socket. You will need to use the IP of our test API (128.32.78.37, port 8084) instead of its hostname to create the socket.
  • Make sure that you implement a valid HTTP client according to the HTTP specification which includes several examples of HTTP exchanges.
  • Note that HTTP headers are required to have a carriage return and newline (CRLF) at the end of each line - it is however not guaranteed that this is the standard line separator on your platform, so take care!
  • Make sure that the connection to the server is properly closed.
1.2 HTTP Headers and Status Codes

From 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 HTTP Status Code
  • The Content-Type header
  • The Cross-Origin Resource Sharing (CORS) headers

The response to your request in the previous exercise should carry the 200 OK HTTP status code. Also have a look at the following four HTTP status codes and look up their exact semantics - you will maybe encounter some of these when dealing with the Activity Streams platform during the course project:

  • 401 Unauthorized
  • 404 Not Found
  • 409 Conflict
  • 415 Unsupported Media Type
1.3 HTTP Content Negotiation

So 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 /posts resource that is more appropriate for machine-machine communication than HTML, we can make use of the HTTP content negotiation mechanism: Set the Accept header of your raw HTTP request to ask the server for a representation of the resource in the JSON format by specifying the appropriate media type. If successful, the Web server will now return a JSON file that contains all forum posts. Display the raw JSON response on the screen.

1.4 HTTP Requests using the requests Library

HTTP 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 /posts resource on the screen.

1.5 Switching Gears: POSTing Data

Up 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 /posts resource. The payload of your POST request should be in the JSON format and have the following structure:

{ 'author' : 'your-name', 'message' : 'your-message' }
Hints:
  • Take care to correctly set the HTTP Content-Type header inside your request.
  • Be careful about the format of your POST payload.
1.6 Submission Instructions for this Task

You 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 python main.py from the command line.

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 XML

In 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:
  • The BART API provides its data in XML format. Use an appropriate library to parse the responses, a good tutorial about this is available at W3CSchools.
  • Your application should run in Firefox and Chrome.
  • We encourage you to make use of the jQuery library for simplifying HTTP requests and parsing of the XML.
2.2: The Same-Origin Policy

The 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 Counter

Visualize the remaining time until the next train using the Countdown widget from the jQuery library.

1423209540 02/05/2015 11:59pm
Please include a description
Additional Comments:
Rating max score to > pts
Please include a rating title

Rubric

Find Rubric
Please include a title
Find a Rubric
Title
You've already rated students with this rubric. Any major changes could affect their assessment results.
 
 
 
 
 
 
 
     
Can't change a rubric once you've started using it.  
Title
Criteria Ratings Pts
This criterion is linked to a Learning Outcome Description of criterion
threshold: 5 pts
Edit criterion description Delete criterion row
5 to >0 pts Full Marks blank
0 to >0 pts No Marks blank_2
This area will be used by the assessor to leave comments related to this criterion.
pts
  / 5 pts
--
Additional Comments
Total Points: 5 out of 5