Assignment 1

Read through the whole assignment before you start working!

Introduction

In this assignment you will make a Web API using node.js.

Objectives

The objectives for the first assignments are to get started:

  • writing javascript
  • building a Web service with Node.js
  • using git for version control

Submission

Deadline for this assignment is 23:59 on 10 September 2017.

Submit the assignment to devilry before the deadline, as a .zip-file containing the project files.

In addition, you should share your private github repository with user olavpo as well as the group teacher in the group you are assigned to.

The Assignment

The assignment is to make a Web-API endpoint with node.js that returns “Car” objects.

Specifically, it should provide an endpoint that supports GET request and returns a JSON representation of a “cars”. Specifically, calls to http://localhost:8081/api/cars should return a single car object, and calls to http://localhost:8081/api/cars?number=N should return N cars (assuming the web service is running on localhost port 8081).

The API should return data in JSON format. Each “Car” object should have the following properties: make, color, registration:

  • make should be randomly selected from a list of at least 3 makes of cars you are free to choose.
  • color should be randomly selected from these options: black, white, red, green, blue.
  • registration, which is the license plate number, should be randomly generated and consist of 2 characters and 6 digits.

Example of single object (car) returned from calling http://localhost:8081/api/cars:

{
    "cars": [
	{
	    "make": "Mercedes-Benz",
	    "color": "black",
	    "registration": "BN223455"
	}
    ]

}

Example of N=3 objects (cars) returned from calling http://localhost:8081/api/cars?number=3:

{
    "cars": [
	{
		"make": "Mercedes-Benz",
		"color": "white",
		"registration": "BN223455"
	},
	{
		"make": "Toyota",
		"color": "red",
		"registration": "AA343221"
	},
	{
		"make": "Volvo",
		"color": "blue",
		"registration": "ZZ532210"
	}
    ]
}

Requests to the /api/cars endpoint with any other method than GET should return Method not allowed.

Version control

You should make a private git repository on github.uio.no and use this actively during the assignment.

Share this repository with user olavpo as well as the group teacher in the group you are assigned to, by adding them as “Contributors”:

  1. open the repository on github.uio.no
  2. select the settings tab, then choose Contributors in the left-side panel
  3. search and add users to add as contributors

Restrictions

For this assignment, you are not allowed to use frameworks or external libraries when making the API, such as Express.js, Koa.js, HAPI etc. Use the default $http class of node.js.

Finished product

The finished project should have a server.js file that can be used to start the service, i.e. with node server.js. You can of course add additional files if/as you see fit in addition to this.

Optional

Optionally, you can add support for different representations of the data, such as XML and CSV, in addition to JSON.

Evaluation

The project will be evaluated based on:

  • the Web service running and providing an API that works as specified in the assignment
  • code style, i.e. that the code is readable and well organised
  • use of git (on github.uio.no) for version control

Commenting your will help those reviewing the code to understand what you have been thinking.