Learning hub

REST APIs, explained from zero

Never heard of a REST API? Start here. This guide teaches the ideas, the vocabulary, and the patterns you need — then shows how to practise them in AOTG.

What is an API?

An API (Application Programming Interface) is a contract that lets one program talk to another in a predictable way. Instead of opening a website in a browser, your app sends a structured request and gets a structured response back.

Think of a restaurant: you don’t walk into the kitchen. You use a menu (the API) to ask for what you want, and the kitchen returns a dish (the response).

Why it matters: almost every modern app — mobile, web, IoT — uses APIs to load data, save accounts, process payments, and more.

What is REST?

REST (Representational State Transfer) is a popular style for designing web APIs. A REST API usually:

You will often hear “REST API”, “RESTful API”, or simply “HTTP API”. In day-to-day work they refer to the same idea: call a URL with a method and get JSON back.

HTTP methods (the verbs)

The method tells the server what kind of action you want. Memorise these five:

Method Meaning Example
GET Read data. Safe — should not change anything. Fetch a list of users
POST Create something new. Create an order
PUT Replace a whole resource. Overwrite a profile
PATCH Update part of a resource. Change only the email
DELETE Remove a resource. Delete a cart item
GET    /users          → list users
GET    /users/42       → one user
POST   /users          → create user
PATCH  /users/42       → update user
DELETE /users/42       → delete user

URLs and resources

A REST URL points at a resource — a thing your API manages, such as /products, /orders, or /users/42.

Query parameters refine a request without changing the resource identity:

GET /products?count=20&category=shoes

Good REST URLs use nouns (resources), not verbs. Prefer POST /orders over /createOrder.

Status codes (how the server answers)

Every response includes a three-digit status code. Learn the families:

Range Meaning Common codes
2xx Success 200 OK, 201 Created, 204 No Content
4xx Client error (your request) 400 Bad Request, 401 Unauthorized, 404 Not Found
5xx Server error 500 Internal Server Error, 503 Unavailable
Always check the status code before trusting the body. A 404 with a helpful JSON message is still a failure.

JSON request and response bodies

JSON (JavaScript Object Notation) is the most common data format for REST APIs. It looks like this:

{
  "id": 42,
  "name": "Ava Nkosi",
  "email": "ava@example.com",
  "active": true
}

On POST / PUT / PATCH you usually send JSON in the request body and set:

Content-Type: application/json

Arrays represent lists: [{...}, {...}]. Nested objects model related data.

Headers

Headers are metadata sent with every request or response. Important ones for beginners:

GET /v1/me HTTP/1.1
Host: api.example.com
Accept: application/json
Authorization: Bearer eyJhbGciOi...

Authentication (who are you?)

Public endpoints need no login. Protected endpoints require proof of identity:

Never put long-lived secrets in frontend source code that anyone can download. Prefer server-side storage or short-lived tokens.

Idempotency and safety (bonus ideas)

Practice with AOTG

Reading alone is not enough. AOTG lets you generate realistic JSON and stand up temporary mock REST endpoints so you can call them from Postman, curl, or your frontend.

1. Generate sample data

Describe a schema and get JSON records you can use in tests and demos.

2. Create a mock API

Publish a temporary REST URL that returns schema-shaped responses.

3. Import OpenAPI

Turn an OpenAPI document into a mock project with routes ready to call.

# Example: call a mock collection (replace BASE with your mock URL)
curl "$BASE/products?count=5"

# Create an item
curl -X POST "$BASE/orders" \
  -H "Content-Type: application/json" \
  -d '{"total":42,"status":"pending"}'

Open the app Mock recipes AOTG OpenAPI Create a free account

Quick glossary

Endpoint
A specific URL + method combination, e.g. GET /users.
Payload / body
The data sent with or returned by a request.
Schema
A description of the shape of data (fields and types).
OpenAPI
A standard document that describes a REST API’s endpoints and models.
Mock API
A fake backend that returns realistic responses without a real database.
Rate limit
A cap on how many requests you may make in a time window.