Networks and the web · A level · OCR H446 1.3.3, AQA 7517 4.9.2.2, Eduqas A500QS 2.5 · about 30 min
Peer to peer and client server, websockets, CRUD and REST with JSON, and thin versus thick clients.
[1 mark]Which HTTP method and SQL statement match the CRUD operation Update?
[1 mark]How does the websocket protocol differ from ordinary HTTP requests?
[1 mark]Why is JSON often preferred to XML for web APIs? Choose all that apply.
Tick every answer that is true.
[1 mark]A REST API receives DELETE /robots/7, but there is no robot 7. Which status code should it return?
[1 mark]Which are advantages of thin-client computing? Choose all that apply.
Tick every answer that is true.
[1 mark]Which is a disadvantage of a peer-to-peer network compared with client-server?
Turn the robot into a tiny REST server. The Client on this mat sends six requests over the radio, one a second. Each is words separated by single spaces: a method, a path, and for some an extra value.
The robot has two kinds of resource: /led, its LED colour (starting as off), and /moves/<id>, the moves it has made, each stored as its distance in whole centimetres with ids counting from 1. Handle each request like this:
| Request | What to do | Send |
|---|---|---|
| GET /led | nothing | 200 <colour> |
| PUT /led <colour> | set the LED to that colour name | 200 <colour> |
| POST /moves <cm> | drive forward <cm> cm at speed 50, store it under the next id | 201 /moves/<id> |
| GET /moves/<id> | nothing | 200 <cm>, or 404 if there is no such move |
| DELETE /moves/<id> | remove the move | 204, or 404 if there is no such move |
| any other path | nothing | 404 |
After sending each response, print <request> -> <response>. Stop after the sixth request, so the output is 6 lines. Check messages() every 0.1 s, and build responses from your stored resources rather than typing them.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
colour = "off"
moves = {}
next_id = 1
wait(6)
for sender, text in messages():
print(text)Plan your program here, then type it in and press Run.
405 for methods a resource does not support, such as DELETE /led.200 {"id": 1, "cm": 20}.