• Home   /  
  • Archive by category "1"

Assignments On The Web


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)


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 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 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).

  • Use the Python socket module to create a basic TCP socket. You will need to use the IP of our test API (, 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 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 resource that is more appropriate for machine-machine communication than HTML, we can make use of the HTTP content negotiation mechanism: Set the 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 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 resource. The payload of your POST request should be in the JSON format and have the following structure:

{ 'author' : 'your-name', 'message' : 'your-message' }
  • 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 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.

  • 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 widget from the jQuery library.

Jump to Main Content

  • Patents
  • Trademarks
  • IP Policy
  • About Us
    • Back
    • About Us Home
    • Events
    • Executive Biographies
    • Find by Subject A-Z
    • News & Updates
    • Organizational Offices
      • Back
      • Office of Policy and International Affairs
      • Office of the Chief Administrative Officer
      • Office of the Chief Communications Officer
      • Office of the Chief Financial Officer
      • Office of the Chief Information Officer
      • Office of the Commissioner for Patents
        • Back
        • Office of the Commissioner for Patents Home
        • Manual of Patent Examining Procedure (MPEP) Staff
        • Office of Patent Legal Administration
        • Office of Petitions
        • Office of the Deputy Commissioner for International Patent Cooperation
        • Office of the Deputy Commissioner for Patent Administration
        • Office of the Deputy Commissioner for Patent Operations
          • Back
          • Office of the Deputy Commissioner for Patent Operations Home
          • TC 1600 - Biotechnology and Organic Chemistry
          • TC 1700 - Chemical and Materials Engineering
          • TC 2100 - Computer Architecture, Software, and Information Security
          • TC 2400 - Computer Networks, Multiplex communication, Video Distribution, and Security
          • TC 2600 - Communications
          • TC 2800 - Semiconductors, Electrical and Optical Systems and Components
          • TC 2900 - Designs
          • TC 3600 - Transportation, Construction, Electronic Commerce, Agriculture, National Security and License & Review
          • TC 3700 - Mechanical Engineering, Manufacturing, Products
      • Office of the Commissioner for Trademarks
      • Office of the General Counsel
      • Office of the Under Secretary and Director
      • Patent Trial and Appeal Board
      • Public Advisory Committees
      • Trademark Trial and Appeal Board
    • Performance and Planning
    • USPTO Locations
    • Vendor Information
  • Learning and Resources

One thought on “Assignments On The Web

Leave a comment

L'indirizzo email non verrà pubblicato. I campi obbligatori sono contrassegnati *