APIs for Product Managers
How requests, methods, status codes, endpoints and JSON fit together, using an order as the running example. No coding needed.
1. What an API is
An API (Application Programming Interface) is a set of rules that lets one program ask another for something. Apps rarely hold their own business data. They ask a server, and the server answers.
Think of a restaurant. You are the user, the waiter is the API, and the kitchen is the backend. You never go into the kitchen, and the waiter takes your order in a fixed format.
Every API call has two halves:
- Request (from the app): a method (what to do), an endpoint (the address to act on), headers (extra details such as the login), and often a body (the data, usually in JSON).
- Response (from the server): a status code (the outcome), and often a body (the result).
2. Worked example: placing an order
The user taps Place order. Here is what happens behind the screen.
- The app builds the request.
POST /orders
Content-Type: application/json
Authorization: Bearer <login token>
{
"customerId": 123,
"productId": 456,
"quantity": 2,
"amount": 1500
} - The API checks it first. Is the user logged in (otherwise
401)? Is the JSON valid with every required field (otherwise400)? Does the product exist (otherwise404)? - The backend does the work: it creates the order, reserves stock and calls the payment step.
- The API replies
201 Createdwith the new order: ID 789, status Confirmed. The app shows "Order placed".
What the API needs before it will accept a request
- The exact endpoint and method (
POST /orders) - Required fields with the right types.
customerIdmust be a number, not"123", if the API says so. - Authentication: usually a login token or an API key
- The
Content-Type: application/jsonheader - Documentation of all of the above, often an OpenAPI (Swagger) specification
How payment usually works
The example above shows the order and its result, not every payment step. The usual pattern is:
- The order is created first, usually as
pending_payment. - The backend sends the charge to a payment provider. Card details go to the provider directly, which keeps most card data out of your own systems.
- The provider approves or declines, and returns the result.
- On success the order becomes
Confirmed. Some designs finish inside one request, as in the example. Others returnpendingand send a later notification, called a webhook.
- Is
amountin rupees or paise? Write it in the specification. - Does the server recalculate the price from the product and quantity? It should. If it trusts the
amountthe app sends, a user could change the price. - If payment is declined after the order exists, is the order cancelled or left pending?
3. HTTP methods: what each one means
A method says what to do with the thing named in the endpoint. Two properties matter for product work. Safe means the call changes nothing. Idempotent means that repeating the same call leaves the same result, which matters when a network error hides the answer and the app retries.
| Method | Purpose | Example | Safe | Idempotent |
|---|---|---|---|---|
GET | Read data | /customers/123 | Yes | Yes |
POST | Create or start something | /orders | No | No |
PUT | Replace the whole record | /customers/123 | No | Yes |
PATCH | Change selected fields | /customers/123 | No | Not guaranteed |
DELETE | Remove a record | /addresses/123 | No | Yes |
200 OK with the customer as JSON. A missing customer returns 404 Not Found. Product takeaway: GET is safe to repeat, so it can be cached.201 Created. Product takeaway: repeating a POST can create duplicates unless the API supports idempotency keys, a unique ID sent with each attempt.city, PUT can clear it. Product takeaway: PUT means a full update; use PATCH to change one field.{"phone": "9876543210"}. Product takeaway: use PATCH for a single setting such as a notification preference.204 No Content (or 200, or 404 if it is already gone). Product takeaway: check whether deletion is permanent or soft, and any audit or legal rules, before you specify it.4. Status codes: reading the first digit
The first digit tells you who has to act.
| Range | Meaning | Who acts |
|---|---|---|
| 1xx | Informational: still in progress | Rarely visible |
| 2xx | Success | Nobody |
| 3xx | Redirect: a new address to follow | The app |
| 4xx | Client error: the request or the access was wrong | The UI or the data |
| 5xx | Server error: the server failed | Engineering |
Common codes:
| Code | Name | What it means for the product |
|---|---|---|
200 | OK | Customer details returned |
201 | Created | New order created |
204 | No Content | Deleted, nothing returned |
301 | Moved Permanently | The record has a new address |
304 | Not Modified | Use the copy you already have |
400 | Bad Request | The data sent was invalid |
401 | Unauthorized | Not logged in, or the login has expired |
403 | Forbidden | Logged in, but not allowed to do this |
404 | Not Found | The order or record does not exist |
409 | Conflict | Clashes with existing data, such as a duplicate |
429 | Too Many Requests | Rate limit reached: retry later |
500 | Internal Server Error | Unexpected failure on the server |
503 | Service Unavailable | Service down or overloaded |
504 | Gateway Timeout | Another service did not answer in time |
5. Endpoints: the address structure
An endpoint is the specific address that performs an action. Each part has a job:
https://api.shop.com /v1 /customers /123 /orders ?status=paid&limit=10
- Base address: where the API lives.
- /v1: the version. It lets the API change without breaking older apps.
- /customers: the resource, written as a plural noun.
- /123: which one. This is a path parameter.
- /orders: a related resource under that customer.
- ?status=paid&limit=10: query parameters, covered in the next part.
Design rules: use nouns, not actions (/orders, not /createOrder), keep collection names plural, and let the method carry the action.
6. Parameters: where the information goes
A parameter is a piece of information the request passes to the API. Each kind of parameter has its own place in the request, and each answers a different question.
| Kind | Where it sits | Question it answers | Example |
|---|---|---|---|
| Path | In the URL path, between slashes | Which specific record? | /orders/123 |
| Query | After the ? | How should the results be filtered, sorted or paged? | ?status=shipped |
| Header | In the request headers | Who is asking, and in what format? | Authorization: Bearer … |
| Body | In the JSON body | What data should be created or changed? | {"quantity": 2} |
Path parameters identify one record
A path parameter is a value inside the URL path that points at one resource. Read the request from left to right:
GET /orders/123
- GET is the action: read.
- /orders identifies the resource type: the collection of orders.
- 123 identifies the specific order: the path parameter.
The same pattern works for other resources:
GET /customers/456: one customerGET /products/789: one productGET /shipments/12345: one shipment, so you can check its status
Business use cases
- Retrieve a customer's profile
- View a specific order
- Check the status of a shipment
- Retrieve a particular product
Common mistakes with path parameters
- Wrong or missing ID. The API returns
404 Not Found. Check that the app passes the right ID, for example a shipment number instead of an order number. - Changing the type. If the API expects a number,
/orders/abcwill fail. Check the documentation for each ID type. - Guessable IDs without access checks. If the ID is simply 1, 2, 3, a user can try other numbers and read someone else's order. The server must check that the logged-in user is allowed to see the record, even when the ID is valid. This is a common security bug, and the answer is an access check on every request.
Path or query? A quick test
Ask whether the value names a specific thing or only narrows a list. /orders/123 names one order, so it is a path parameter. /orders?status=shipped narrows the list of orders, so it is a query parameter. Both can appear in one request: GET /customers/456/orders?status=paid means "paid orders for customer 456".
7. Query parameters: filtering and sorting
Query parameters follow the ?. They are name=value pairs joined by &. They narrow or order the results, and do not change the method.
GET /orders?status=shipped&sort=-created_at&limit=20&page=2
status=shipped: only shipped orderssort=-created_at: newest first (the minus sign means descending)limit=20: 20 results per pagepage=2: the second page
Spaces are encoded, so "New Delhi" becomes New%20Delhi in the address.
8. JSON: the format of the instructions
JSON (JavaScript Object Notation) is the text format most APIs use for data. Four rules cover most cases:
- Objects go in
{ }and hold name and value pairs. - Lists go in
[ ]. - Text is in double quotes:
"name": "Rahul Kumar". - Numbers, true, false and null take no quotes:
"quantity": 2. A trailing comma or a single quote makes the whole message invalid.
{
"customerId": 123,
"productId": 456,
"quantity": 2,
"amount": 1500
}
If quantity were sent as "two", the API would reply 400 Bad Request. The reply is JSON too, so the app can read the order ID and show it to the user.
9. Key takeaways
- An API is a set of rules for asking another program for something.
- GET reads, POST creates, PUT replaces, PATCH changes some fields, DELETE removes.
- Status codes tell you who has to act: 2xx success, 4xx the request or access, 5xx the server.
- Endpoints are nouns in a clear hierarchy. Path parameters name one record; query parameters filter and sort.
- JSON bodies are instructions the server checks before it acts.
- Always ask: what happens if the request is repeated, and does the server check prices and permissions itself?
10. Practice exercise
- Write the request for a customer changing only their phone number. Choose the method and endpoint, and write the body.
- A user reports "I can see my order but cannot cancel it" and the app shows an error. List three status codes that could explain it, and what each one tells the engineer.
- Your payment step times out and the user taps Pay again. What can go wrong? Name the safeguard you would specify.
- Write the request to show a customer's paid orders from last month. Mark which part is a path parameter and which parts are query parameters.
Check your answers against sections 2, 3, 4, 6 and the payment steps in section 2.
11. Quick check
1. Which method should you use to update a customer's phone number only?
PATCH, because it changes selected fields. PUT would replace the whole record.
2. A request returns 401. What is the most likely cause?
The user is not logged in, or the login has expired. It is not a problem with the data.
3. In GET /shipments/12345, which part is the path parameter?
12345. It identifies the one shipment. /shipments names the resource type.
4. Why must the server check access even when the ID is valid?
Because a user can guess or change IDs. A valid ID does not prove the user is allowed to see that record.
5. Why should the server, not the app, set the order price?
The app can be changed by the user, so the server must recalculate the price from the product and quantity.
Examples are simplified for learning. Real APIs differ in names, limits and error formats. Always read the documentation of the API you use.