In this lesson
- The Big Idea
- Client and Server: the Request–Response Cycle
- HTTP and HTTPS: the Rules of the Conversation and How to Protect It
- HTTP Requests and Responses: Method and Status Code
- Application Programming Interface (API) and JSON
- The Whole Picture: One Request's Journey
- Try It Yourself
- Common Mistakes
- Key Points
- FAQ
The Big Idea
In the last lesson you saw that the frontend and backend work together to carry out what the user asks for. This lesson is about how they talk. When you click a link or start a search, your device sends a request across the network to a service on a server; the server processes it and sends back a response. The side that asks is called the client. The conversation follows rules set by a protocol such as HTTP, it can be protected with HTTPS, every request carries a method that says what it wants, and every response carries a status code that says how it went.
Client and Server: the Request–Response Cycle
In many web applications, communication involves two sides with clear roles:
- Client: a program or device that sends a request to another service, asking for data or processing. The two classic examples are a web browser and a phone app. Your banking app or a delivery app is just as much a client as a browser is.
- Server: the side that receives requests from clients, processes them and sends back responses.
The same cycle repeats thousands of times a day: the client sends a request and the server replies with a response. One server can serve many clients at once: your laptop, your brother's phone and a tablet in another school can all send requests to the same service, and each gets its own response.
Linking this to the previous lesson
In lesson 3-1 we split a web application into a frontend, a backend and a database. The frontend runs on the client (in the browser or app) and the backend runs on the server. So when "the frontend sends the search words to the backend", that is really a request travelling from client to server, and when it "displays the results", that happens after the response arrives.
HTTP and HTTPS: the Rules of the Conversation and How to Protect It
HTTP: the agreed language
For the client and server to understand each other, they need shared rules that set the shape of each message, its order and what it carries. Those rules are called a protocol. HTTP (Hypertext Transfer Protocol) is the protocol used to exchange messages between a client and a server on the web. Every request your browser sends and every response a server returns is written according to HTTP's rules.
HTTPS: the same HTTP, inside a secure connection
On its way, a message passes through many devices and networks: café Wi-Fi, your internet provider's equipment and more. If it is sent over plain HTTP, an eavesdropper along the route may be able to read it, or even change it.
That is where HTTPS comes in. It means using HTTP over a secure TLS connection. TLS (Transport Layer Security) helps with three things:
- Confidentiality: an eavesdropper cannot easily read the content while it travels.
- Integrity: the content cannot easily be changed on the way without that being detected.
- Server authentication: checking that you are really talking to the right server and not a fake one pretending to be it.
Notice that HTTPS is not a different language: the messages are still HTTP messages, just travelling inside a protected "tube". You can tell a site uses HTTPS when its address starts with https://.
HTTP Requests and Responses: Method and Status Code
Every HTTP message carries information that helps the other side understand it. The two most important pieces in this lesson are the method in the request and the status code in the response.
HTTP request method: what do you want from the server?
The HTTP request method is information inside the request that says what kind of operation is wanted. The book focuses on two:
| Method | Usual role | Examples |
|---|---|---|
| GET | Usually requests a resource or data from the server | Viewing a web page, getting search results |
| POST | Usually sends data for the server to process | Sending login details, submitting a form |
Think of it like this: GET means "give me", and POST means "take this data and process it". Note the word usually in the Arabic edition: this is each method's normal use, and that is what exam questions ask about.
Here is a simple GET request asking an online shop for search results for the word "dictionary":
GET /search?q=dictionary HTTP/1.1
Host: shop.exampleThe first line carries the method (GET), then the path being requested on the server, then the protocol version. The second line names the site. A login request, by contrast, uses POST, because it sends data for the server to process and check:
POST /login HTTP/1.1
Host: portal.school.example
Content-Type: application/x-www-form-urlencoded
user=mona&pass=1234The data being sent (username and password) comes after a blank line, in the body of the request. Because it is sensitive, this request must travel over HTTPS, not plain HTTP.
HTTP status code: how did it go?
The response from the server includes a number that reports the result of processing the request. It is called the HTTP status code. The three in the book:
| Code | Meaning |
|---|---|
| 200 | Success: the request was processed successfully |
| 404 | The requested resource does not exist at this address |
| 500 | Internal server error that stopped the server from completing the request; the code alone does not identify the detailed cause |
Be precise about the difference between 404 and 500:
- With 404, the request reached the server and the server is working, but it found nothing at that address: maybe the link is mistyped, or the page was deleted or moved. The Arabic edition says "requested resource", and a resource can be a page, an image, a file or data.
- With 500, something went wrong inside the server itself and stopped it finishing the request. The code doesn't say what exactly; finding the cause needs investigation on the server side.
This is what the first line of a response, the one carrying the code, looks like:
HTTP/1.1 404 Not FoundHTTP/1.1 500 Internal Server ErrorApplication Programming Interface (API) and JSON
What is an API?
Not every request comes from a person opening a page. Very often a program asks another program for data. That needs an API (Application Programming Interface): a set of clear rules that lets one program request data or functions from another program. It defines what you can ask for, where to ask, and what shape the answer will take.
Examples close to you:
- The weather app on your phone doesn't measure the temperature itself; it sends a request to a weather service's API, which returns today's forecast.
- An online shop's frontend may send a request to a backend service through an API and receive the product list to display.
- One school's system might request today's timetable from another school's system through an API instead of copying it by hand.
What is JSON?
When an API returns data, it may use JSON (JavaScript Object Notation). JSON is a common text format for representing and exchanging structured data, built from three things:
- Objects: a set of key–value pairs, written between curly braces.
- Arrays: an ordered list of values between square brackets.
- Simple values: such as text in double quotes, numbers, and true/false.
Because it is organised text, many programming languages and tools support it, so a server written in one language and a phone app written in another can swap data easily.
Activity from the Arabic book: read the data (JSON)
Look at this data:
{
"city": "Cairo",
"temperature": 31
}Task: name one key and its matching value. The data is a single object with two pairs:
- Key
"city"with value"Cairo", which is text (note the quotes). - Key
"temperature"with value31, which is a number (no quotes).
Naming either pair is enough. The key always comes before the colon and the value after it.
Here is a slightly bigger example a weather service might return, with text, a number, a true/false value and an array:
{
"city": "Alexandria",
"temperature": 27,
"rain": false,
"nextDays": [26, 28, 29]
}The value of "rain" is false (no rain), and the value of "nextDays" is an array of three temperatures for the coming days. This is what might arrive in the body of a successful response:
HTTP/1.1 200 OK
Content-Type: application/json
{"city": "Alexandria", "temperature": 27}The first line carries status code 200, and the second tells the client that the body is written in JSON.
The Whole Picture: One Request's Journey
Let's put everything together. A student called Mona opens her school portal to see today's timetable:
- Mona types the portal address, which starts with
https://, and the browser (client) connects to the server over a secure TLS connection. - She logs in: the browser sends a
POSTrequest carrying her username and password inside the protected connection. - The server checks the details and returns a response with status code 200.
- She clicks "Today's timetable": the browser sends a
GETrequest for the timetable. - The server might request the timetable from another system through an API, receive it as JSON, prepare it and send it back to the browser.
- If Mona clicks a link to an old page that was deleted, the server returns 404. If an internal fault happens in the server's program while preparing the timetable, it returns 500.
Try It Yourself
Common Mistakes
"HTTPS is a completely different protocol from HTTP"
HTTPS is not a new language. The messages are still HTTP messages, with the same methods and the same status codes.
HTTPS is HTTP used over a secure TLS connection, which protects confidentiality and integrity and helps authenticate the server.
"A 404 means the server is broken"
With a 404 the server is working and has actually answered you; it just didn't find the requested resource at that address. An internal server fault has a different code.
404 = the requested resource does not exist at this address; 500 = an internal server error stopped the request being completed.
"A 500 tells me exactly what went wrong"
500 only says an internal error happened on the server. On its own it doesn't say whether it was a bug in the program or something else.
Finding the detailed cause of a 500 needs investigation on the server side, not just the code.
"GET is for sending and POST is for requesting"
That is exactly the reverse of normal use, and it is a favourite trap in true/false questions.
GET is usually used to request a resource or data (viewing a page, search results); POST is usually used to send data for the server to process (login, forms).
"An API and JSON are the same thing", or "JSON is encrypted"
An API is the set of rules letting one program request data or functions from another; JSON is just a text format the data may come in. JSON is readable text with no encryption at all.
An API may return data as JSON, and protection in transit is HTTPS's job.
Key Points
- A client is a program or device that sends a request (such as a browser or phone app); a server receives requests, processes them and returns responses.
- The request–response model is basic to many web applications, though other means of communication can be used when needed.
- HTTP is the protocol for exchanging messages between client and server on the web.
- HTTPS is HTTP over a secure TLS connection, protecting confidentiality and integrity and helping authenticate the server; such sites have addresses starting
https://. - The HTTP request method states the kind of operation:
GETusually requests a resource or data;POSTusually sends data for the server to process. - The HTTP status code reports the result:
200success,404resource not at this address,500internal server error whose detailed cause the code alone doesn't give. - An API is a set of clear rules letting one program request data or functions from another, and it may return data as JSON.
- JSON is a common text format for structured data built from objects (key–value pairs), arrays and simple values, supported by many languages.
FAQ
What is the difference between HTTP and HTTPS in one line?
HTTP sets the rules for exchanging messages between client and server; HTTPS is the same HTTP over a secure TLS connection, protecting the messages' confidentiality and integrity in transit and helping verify the server's identity. You can spot it by an address starting with https://.
Does a phone app count as a client, like a browser?
Yes. In the Arabic edition a client is any program or device that sends a request to another service, and the book gives the web browser and the phone app as examples.
If I see a 404 error, is my internet connection the problem?
Usually not. Getting a 404 means your request arrived and the server answered, but it found no resource at that address. Check the link: it may be mistyped, or the page may have been deleted or moved.
How do I find the key and the value in JSON data?
Inside an object, each pair has the key before the colon and the value after it. In "city": "Cairo" the key is city and the value is Cairo; in "temperature": 31 the key is temperature and the value is the number 31.