Summary: Client and Server
The final test quiz of the whole client-server introductory series: check how well you have absorbed the material. A cheat sheet on methods and response codes comes first, followed by 23 questions on every topic covered.
About the product
Hi! You’ve completed the whole introductory series on the client and the server: GET, POST, PATCH, PUT, DELETE and response codes. Great work! All that’s left is to put it all together.
Thanks! What’s next?
Kadri has prepared a final check: a short cheat sheet and questions on the whole series. Kadri is waiting for you in the meeting room.
Hi! Well done for getting to the end. Before you test yourself, let’s put everything into one picture.
Sure! What are the main things to remember?
The client sends a request, the server processes it, goes to the database if needed, and then returns a response: a status code and data, usually in JSON. The client never goes to the database itself. Here are two cheat sheets:
CRUD and HTTP methods
- Create:
POST, success —201 Created - Read:
GET, success —200 OK - Update:
PATCH(part of the data) orPUT(the whole object), success —200 OK - Delete:
DELETE, success —204 No Content
Response codes
2xx— success.200 OKwith an empty list[]is also a success, not an error3xx— a redirect: the resource has moved. For example, the old/salepage was removed and the deals now live at/promo. ToGET /salethe server answers301 Moved Permanentlyand puts the new address/promoin theLocationheader, and the browser goes there on its own. The tester checks that the old link leads to the right page, not to a4044xx— a client error:401— not logged in,404— not found,405— the method is not allowed5xx— a server error:500— something broke on the server,503— the server is temporarily unavailable or overloaded
And the main thing for a tester: check not only the response code, but also the data in the database and what the user sees.
Ready to test myself!
Then let’s go! I’ll ask 21 questions on the whole series in random order, as if we were talking through real work situations. If you make a mistake, I’ll give you a hint and you can answer again. Answers that are right on the first try count.
Let’s warm up. The server sent this response. What is the product called?
{
"id": 5,
"name": "Rye bread",
"price": 1.79
}A customer opened the catalogue and the server returned this list. How many products will the customer see?
[
{"id": 2, "name": "Cherry tomatoes, 250 g", "price": 2.29},
{"id": 7, "name": "Salted herring, 300 g", "price": 3.29}
]By the way, yesterday I saw in the logs that a customer requested the catalogue five times in a row: five GET requests. Should I worry about the products in the database?
Now about the admin panel. An administrator has just added a new product. Which method went to the server, and which response do we expect by the standard?
Here’s a real-life story: an administrator accidentally pressed “Add product” twice in a row with the same data. Let’s look in the database — what’s there?
A little task from me: we need to change only the price of a product and leave everything else alone. Which method will you choose?
Imagine you need to delete the product with id 5. What will the request look like, and which response will you expect?
One more situation. The old deals page /sale was removed, and the deals now live at /promo. But customers still have links to /sale in old newsletters. What should the server answer to GET /sale?
Now let’s talk about errors. An administrator logged in to the admin panel and got an access code that is valid for 15 minutes. While filling in the product card, they were interrupted by a phone call, and the 15 minutes passed. Now they click “Add product”. What will the server answer?
Here’s a more interesting case: the client sent DELETE to the whole list /api/v1/products, but only GET and POST are allowed there. Which code comes back?
A new tester brought me a “bug”: the shop has just opened, there are no products, and the server answers 200 OK with an empty list []. Do we file a bug report?
You send a request and the server answers 500. Whose fault is it?
Rye bread cost 1.79. An administrator sent a PATCH with the new price 2.19, and the server answered 200 OK. You open the product with GET, and it still shows 1.79. Do we file a bug?
An administrator added a product: the server answered 201 Created, and GET /api/v1/products returns the new product. But the customer doesn’t see it on the catalogue page. Where should we look for the problem?
Look at the request and the response. What’s wrong here?
DELETE /api/v1/products/5
← 200 OK
{
"error": "Product not found"
}You sent DELETE /api/v1/products/5 and got 204 No Content. To check, you send exactly the same request again. What will the server answer?
A customer opened a link to a product the shop never had: GET /api/v1/products/999. Which response is correct?
Black Friday: a huge number of customers came to the shop, and some of them get the response 503 Service Unavailable. What does it mean?
A developer says the server’s response is fine. Take a closer look: is everything right here?
{
"id": 5,
"name": "Rye bread",
"price": "1.79"
}You need to get the product with id 5. A colleague suggests sending GET /api/v1/products with the body { "id": 5 }. Will it work the way they planned?
You are deleting a product: DELETE /api/v1/products/5. Does this request need a body?
The final check is done, and the introductory Client-Server series is complete! To reinforce it, a self-study task is next: you’ll draw a CRUD diagram for a real Todo app.
Quick reference
Client, server and database
The client sends a request, the server processes it, goes to the database if needed, and returns a response. The client never goes to the database directly.
JSON
The data in a response usually comes in JSON. An object is in curly braces { } with “key: value” pairs, a list of objects is in square brackets [ ]. An empty list [] means “no data”, not an error.
Methods and CRUD
POST /api/v1/products — create (201 Created), GET /api/v1/products — read (200 OK), PATCH /api/v1/products/3 — change part of the data, PUT /api/v1/products/3 — replace completely (both 200 OK), DELETE /api/v1/products/3 — delete (204 No Content).
Repeating requests
GET can be repeated any number of times: it changes nothing. Every POST creates a new record, so a repeat gives a duplicate. A repeated DELETE doesn’t change the database, but returns 404.
Response codes
2xx is success (200 with an empty list is a success too). 4xx is a client error: 401 — not logged in, 404 — not found, 405 — the method is not allowed. 5xx is a server error: 500 — something broke, 503 — the server is temporarily overloaded.
What a tester checks
The response code, the data in the database and what the user sees: a clear message, an up-to-date list, no hanging.