The GET Method: Loading the Catalogue
How the client, the server, and the database exchange data, using an online shop loading its catalogue.
About the product
BB Food is an online grocery store with home delivery. A customer opens the website, browses the catalogue, picks groceries, and places an order.
The catalogue currently has 7 products. Before testing the website, let’s see how it works: what happens in the browser, what happens on the server, and where the products are stored.
Let’s start with the main thing: how almost any web application works.
Let’s figure it out!
It has two sides. The client is what a person uses: a browser or a mobile app. The server is a program on another computer that runs around the clock and listens for requests. The client asks, and the server answers.
The customer’s browser sends the request “give me the product list”, and a program on another computer answers it. Which is the client and which is the server?
Hey, so where does the server get its data?
The server keeps data in a database. It is a separate program, often even on a separate computer. The client never goes to the database directly: only the server talks to it.
The server and the database exchange requests too, but in their own language — SQL.
So how do they even understand each other?
They have their own special language — the HTTP protocol. It’s the most common one, but there are others too. The client sends a request, and the server returns a response. Both the request and the response have a strict format. Here is what a request looks like. A request can actually have more parts, but one step at a time — let’s start with a simple version that has two parts:
Request
GET /api/v1/products
- Part 1. The method — what to do.
GETmeans “get”. There are other methods too — we’ll talk about them later - Part 2. The address — what to do it with.
/api/v1/productsis the product list
Got it! And what does the server send back?
In the simple version, the response has two parts too:
Response
200 OK
[
{
"id": 1,
"name": "Bananas, 1 kg",
"price": 1.49
},
{
"id": 2,
"name": "Cherry tomatoes, 250 g",
"price": 2.29
},
…
]- Part 1. The status code — how it went.
200 OKmeans “success” - Part 2. The response body — the data itself, usually in JSON
Let’s check you’ve got it. Where does the client get the product list from?
Wait, what is JSON?
JSON is a simple text format that programs use to send each other data. People can read it easily too, so a tester sees it all the time. JSON isn’t the only such format — there are others too — but let’s start with it: it’s the one you’ll see most often.
The simplest kind is an object. It is written in curly braces { } and is made of “key: value” pairs.
A key is the field name in quotes. A value is text in quotes or a number without quotes. The pairs are separated by commas.
This is what one product looks like:
{
"id": 3,
"name": "Milk 2.5%, 1 l",
"price": 1.19
}It reads easily: the product has id 3, the name “Milk 2.5%, 1 l” and the price 1.19. Note that numbers are written without quotes.
Let’s practise a bit. The server sent this object. What is the price of this product?
{
"id": 4,
"name": "Gouda cheese, 200 g",
"price": 2.99
}And if there are lots of products, what then?
Then the objects are put into a list, also called an array. A list is written in square brackets [ ], and the objects inside are separated by commas. That’s exactly how the server sends our catalogue:
[
{"id": 1, "name": "Bananas, 1 kg", "price": 1.49},
{"id": 2, "name": "Cherry tomatoes, 250 g", "price": 2.29}
]If there are no products at all, an empty list [] comes back. It’s not an error, it just means “no data” — remember that, it will come in handy.
Here’s one to test your attention: how many products are in this response?
[
{"id": 1, "name": "Bananas, 1 kg", "price": 1.49},
{"id": 5, "name": "Rye bread", "price": 1.79},
{"id": 6, "name": "Orange juice, 1 l", "price": 2.49}
]Awesome, let’s try it in practice!
Here is the BB Food website. No products are shown on it yet: the browser hasn’t asked the server for anything.
Your task now: press Load products and follow the envelope: client → server → database → server → client.
Application under test
Scenario 1. Positive: the server is running
The server is waiting for requests. Press Load products in the browser to make the client send GET /api/v1/products.
The animation is slowed down: in reality the whole trip takes a few dozen milliseconds.
No products loaded yet.
Couldn’t load the products: a server error occurred (500). Please try again later.
The products have loaded! But they don’t live in the browser: they are stored in the database on the server side, and the client gets them with a request every time.
Oh, can I load the products again?
Yes, of course. The request takes the same path: client → server → database → server → client. But the response always shows the current state of the database: if the products have changed, a different response comes back.
Interesting! So what do the products look like in the database?
Good question! A database keeps data in tables. Our products are in the products table. One row is one product, and one column is one property of it: id is a unique number, name is the name, and price is the price.
When a GET /api/v1/products request comes in, the server runs the SQL query SELECT * FROM products. It means “select all columns of all rows from the products table”. Then the server turns the rows into JSON and sends them to the client.
Here is what the products table looks like in the database:
| id | name | price |
|---|---|---|
| 1 | Bananas, 1 kg | 1.49 |
| 2 | Cherry tomatoes, 250 g | 2.29 |
| 3 | Milk 2.5%, 1 l | 1.19 |
| 4 | Gouda cheese, 200 g | 2.99 |
| 5 | Rye bread | 1.79 |
| 6 | Orange juice, 1 l | 2.49 |
| 7 | Salted herring, 300 g | 3.29 |
And remember: the client never goes to the database itself. Only the server talks to the database.
Compare the products on the website with this table: did every one reach the client?
A customer presses Load products five times in a row. What happens to the products in the database?
We’ve covered the positive scenario. Shall we move on?
Yes, let’s keep going!
Scenario 2. Negative: a server error
So we’ve checked the positive scenario: the server is running and the products reached the client. But a tester is always interested in something else: what if something goes wrong? For example, something breaks on the server. What do you think the user will see then?
Hmm, no idea. Let’s check!
Let’s imagine something has broken on the server.
Your task now: press Load products on the website below and watch what happens.
The server is running and answering, but instead of the products it returned a 500 error: something broke inside the server. Note that a response did arrive, and it has a code. Every code starting with 5 is an error on the server’s side: the user did nothing wrong, and it’s the server that needs fixing.
Remember: 500 is the server’s way of saying “something broke on my side”. Codes starting with 4, on the contrary, say the client made a mistake: for example, asked for something that doesn’t exist.
What should I check here, and why?
Good question! A tester checks not only what works when everything is fine, but also how the app behaves when something breaks. Check three things: the user sees a clear error message rather than a technical code or an empty screen, the app doesn’t hang, and the button can be pressed again. Why? Servers break, and the user shouldn’t be lost when it happens.
Report the error to the developers
The developers have fixed the server. Hooray! It’s good that everything works again, and we can carry on testing.
Your task now: press Load products — this time the request should succeed.
Great, everything works! But let’s take a little break for now — let’s go grab a coffee ☕
Let’s go!
Quick reference
Client
The program a person uses: a browser or a mobile app. The client shows the interface and asks the server for data.
Server
A program that constantly listens for incoming requests, processes them, and sends back a response. The server never writes to anyone first: it only answers clients’ requests.
Database
Storage where data is kept in tables. The client never talks to the database directly: only the server works with it.
Request and response
The client and the server talk over HTTP. A request has a method (what to do) and an address (what to do it with). A response has a status code (how it went) and a body with the data, most often in JSON.
JSON
A text data format. An object is written in curly braces { } as “key: value” pairs, for example {"id": 3, "price": 1.19}. Text goes in quotes, numbers go without quotes. A list of objects is written in square brackets [ ], separated by commas. An empty list [] means “no data”, not an error.
The GET method and code 200
GET /api/v1/products means “get data”. It changes nothing on the server, so it can be repeated any number of times. Code 200 OK means the request succeeded.
Code 500
The response a server sends when something has broken on its own side. Codes starting with 5 are server errors, codes starting with 4 are client errors. A tester checks that the user sees a clear error message and the app doesn’t hang.