Written Examination DIT341 – Web and Mobile Development
Monday, October 26th, 2020, 08:30 – 12:30
Contact Persons During Exam:
(+46 733 05 69 14) (+46 733 42 41 26)
Copyright By PowCoder代写 加微信 powcoder
Allowed Aides:
All material can be used in this home exam. However, the exam is individual, and collaborating or sharing solutions with other students is strictly forbidden.
Exam results will be made available no later than 15 working days after the exam date through Ladok.
Total Points: 100
Grade Limits: 0 – 49 points: U, 50 – 84 points: G, >=85 points: VG
The exam review will take place over Zoom following publishing of grades.
1 Backend Development (16P)
Complete the code snippet of an Express app on the next page of the exam paper. Implement a collection endpoint that allows clients to retrieve all elements of the array storage. The endpoint should support a query parameter sort indicating how the response shall be sorted: if a value is given for this parameter (either asc or desc) the results shall be sorted appropriately; if sort is omitted, the result shall be returned in the same order as stored in the array. Return a JSON object. If an invalid value is passed as sorting parameter, return the status code 400 with an appropriate error message in plain text. Select an appropriate endpoint type (HTTP method) for this kind of operation.
Either submit the complete program, or write down only the missing code (in this case refer to the lines in the template via line numbers). Available space is not necessarily indicative of how much code is required. The code snippet is also available on Canvas as code file.
1 var express = require(‘express’);
2 var app = express();
4 var storage = [7, 5, 8, 9, 13, 4]; 5
(‘/numbers’, function(req, res) {
25 function sort_asc(array) {
26 return array.sort((a, b) => a – b);
29 function sort_desc(array) {
30 return array.sort((a, b) => b – a);
33 app.listen(3000);
Figure 1: Complete the Blanks (Express)
2 HTTP and REST APIs (22P)
GitHub is a platform for managing source code. Find below a (strongly simplified) excerpt from the GitHub API.
GET /:organization/repositories
GET /:organization/repositories/:repo
POST /:organization/repositories/
PATCH /:organization/repositories/:repo
PUT /:organization/repositories/:repo
Figure 2: Excerpt of a GitHub-inspired API
Answer the following questions about this API, assuming that it has been designed following the REST principles introduced in the lecture.
Q2.1: Describe what functionality and behavior you would expect from the following API method. What response and status code would you expect from the service in case of a successful request? What would you expect to happen if you invoked the same API method multiple times, with the same URL and body? (4P)
• POST /:organization/repositories/
Q2.2: Assume that you use the following API operation in your program. Name two status codes not indicating success that your application should be prepared for, and discuss briefly which erroneous situations they would represent. (4P)
• GET /:organization/repositories/:repo
Q2.3: What would be a good REST endpoint pattern (following the existing examples) to use if a user wanted to remove a repository? Provide the pattern using the same
notation as above, and explain briefly. Further, give at least one example of a ”technically correct” way to implement a deletion that does not follow good REST practices (and describe why it does not follow good practice). (4P)
Q2.4: Define the concepts of safety and idempotency (for HTTP methods in general). Which of the 5 operations in the above API excerpt would you expect to be safe, and which would you expect to be idempotent? Why? (4P)
Q2.5: Write down a legal, successful HTTP request for the following endpoint (the complete HTTP request message as it will be transferred on the network). You expect a JSON response, and the server has previously set the cookie session=aF36CC. Send a simple JSON object with two fields (your choice) as body. (6P)
• POST /:organization/repositories/
3 Responsive Web Design and CSS (15P)
Complete the code snippet of a simple RWD demonstration on the next page of the exam paper. Add the appropriate CSS and HTML code so that the described behavior is realized, and refer to the screenshots below for expected formatting and behavior. You shall not use Bootstrap or BootstrapVue in this example.
Either submit the complete program, or write down only the missing code (in this case refer to the lines in the template via line numbers). Available space is not necessarily indicative of how much code is required. The code snippet is also available on Canvas as code file.
This is the expected behavior of the HTML page when the screen size exceeds 800 pixels:
This, on the other hand, is what should be shown for smaller screen sizes:
3 4 5 6 7 8 9
20
22