How Servers and APIs Work
What is a Server?
A server is a computer that listens for requests from other computers and responds to them. When you open Instagram on your phone, your phone sends a request to Instagram's servers. The servers look up your feed in a database and send it back.
Servers are not magic -- they are just computers running software that knows how to respond to requests. The key difference between a server and your laptop is:
- A server runs continuously, 24 hours a day, 7 days a week
- A server is optimised to handle thousands of simultaneous connections
- A server is usually accessible over the internet by its IP address or domain name
The Client-Server Model
The internet operates on a client-server model:
- Client: Any device that makes requests (your phone, browser, or another server)
- Server: The computer that receives and responds to requests
Client (Phone/Browser) --> Request --> Server
Client (Phone/Browser) <-- Response <-- Server
This model is behind everything: loading a webpage, logging into your bank, sending a WhatsApp message.
What is an API?
An API (Application Programming Interface) is the set of rules that define how a client can talk to a server. Think of it as a menu at a restaurant:
- The menu shows you what you can order (the available endpoints)
- You place your order (make a request)
- The kitchen prepares your food (the server processes the request)
- The waiter brings it to you (the server sends a response)
A REST API (Representational State Transfer) is the most common type. It organises server interactions around resources (like users, posts, or products) and uses HTTP methods to act on them.
HTTP Methods
HTTP (HyperText Transfer Protocol) defines how messages are sent between clients and servers. The most important HTTP methods are:
| Method | Purpose | Example |
|---|---|---|
| GET | Retrieve data | Get a list of products |
| POST | Create new data | Submit a registration form |
| PUT | Update existing data | Edit a user profile |
| DELETE | Remove data | Delete a comment |
| PATCH | Partially update data | Change just the email address |
Example: A User API
GET /api/users -- Returns all users
GET /api/users/123 -- Returns user with ID 123
POST /api/users -- Creates a new user
PUT /api/users/123 -- Updates all fields of user 123
DELETE /api/users/123 -- Deletes user 123
What is JSON?
When APIs send data, they use a format called JSON (JavaScript Object Notation). JSON is a lightweight, human-readable text format that represents data as key-value pairs.
{
"id": 123,
"name": "Chidi Obi",
"email": "chidi@example.com",
"role": "admin",
"createdAt": "2024-01-15"
}
JSON can represent:
- Strings:
"hello" - Numbers:
42 - Booleans:
trueorfalse - Arrays:
["apple", "banana", "cherry"] - Nested objects:
{ "address": { "city": "Lagos", "country": "Nigeria" } }
Request and Response Anatomy
Every HTTP request has:
- Method: GET, POST, PUT, DELETE, etc.
- URL: The address of the resource
- Headers: Metadata (e.g., content type, authentication token)
- Body (optional): Data sent with POST or PUT requests
Every HTTP response has:
- Status code: A number that tells you what happened
- Headers: Metadata about the response
- Body: The actual data (usually JSON)
HTTP Status Codes
Status codes are three-digit numbers grouped by category:
| Range | Meaning | Examples |
|---|---|---|
| 2xx | Success | 200 OK, 201 Created |
| 3xx | Redirect | 301 Moved Permanently |
| 4xx | Client error | 400 Bad Request, 401 Unauthorised, 404 Not Found |
| 5xx | Server error | 500 Internal Server Error |
When you see "404 Not Found", that is the server telling you the resource you asked for does not exist.
APIs in the Real World
Businesses expose APIs so that other applications can use their services:
- Paystack API: Lets you accept payments in your app
- Google Maps API: Lets you embed maps and get directions
- Twilio API: Lets you send SMS messages programmatically
- OpenAI API: Lets you use artificial intelligence models in your code
As a backend developer, you will both consume third-party APIs and build APIs that others (including your own frontend) can use.
Try it yourself
Key Takeaways
- A server is a computer that runs continuously, listens for requests, and sends back responses.
- The client-server model underpins all internet communication: clients request, servers respond.
- REST APIs use HTTP methods (GET, POST, PUT, DELETE) to perform operations on resources.
- JSON is the standard data format used by APIs to exchange information.
- HTTP status codes communicate the outcome of a request: 2xx success, 4xx client error, 5xx server error.
Quick Quiz
1.In the client-server model, what is the role of the client?
2.Which HTTP method would you use to create a new user account?
3.What does a 404 status code mean?
4.What format do most REST APIs use to exchange data?
Ready to go further?
CareerEx gives you structured 12-week training, live classes every Saturday and Sunday, real tutor feedback, and a certificate. Join the next cohort.
Join CareerEx