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.

Kadri, mentor

Let’s start with the main thing: how almost any web application works.

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.