A dealer's system sends an order, the network cuts the response short, the system sends the order again, and two orders land in the warehouse. Another dealer pulls a 1,000,000-record history page by page and the server slows down the closer it gets to the last pages. A third sends 50 separate requests for the product details of a 50-line order and waits 6 seconds. All three come from the same root: REST API design means deciding in advance how endpoints are named, what each method means, how lists are paged and how an error is explained.
In this guide we walk through the topic with a dealer portal order API: resource naming, HTTP methods, filtering, pagination, error format, Idempotency-Key, batch endpoints, ETag and a short comparison of REST and GraphQL. We focus on the endpoint itself; security, versioning and quotas have their own guides. All figures are representative, not a real measurement or an industry average.
What Is REST API Design and Why Is It a Topic of Its Own?
REST API design is the work of exposing a system's data and operations over HTTP as resources, with consistent rules for addresses, methods, responses and errors. Even if the code works, a weak design makes every new client rediscover the same problems.
The idea is simple: the address names a thing (an order, a dealer, a product), the method says what to do with it, and the status code reports the result. Trouble starts when these three get mixed. We covered general API concepts in our API integration guide; here we design the inside of the endpoint.
We recommend reading: Our integration service
How Should Resources Be Named in a REST API?
Resources get plural nouns; the verb lives in the HTTP method, not in the address. In our example system the resources are dealer, order, line item and product.
| Weak design | Recommended design | Why |
|---|---|---|
POST /createOrder | POST /v1/orders | The verb is in the method; the address names the collection |
GET /getOrder?id=7 | GET /v1/orders/7 | A single resource lives in the path; the query string is for filters |
POST /cancelOrder | POST /v1/orders/7/cancellations | The action is expressed as a resource that gets created |
GET /dealerOrders | GET /v1/dealers/B-204/orders | Relationships nest in the path; two levels at most |
DELETE /removeOrder | DELETE /v1/orders/7 | Only for drafts; a confirmed order returns 409 |
Small rules create consistency: one spelling convention (for example snake_case only), UTC dates in ISO 8601, amounts together with a currency. Keep nesting to two levels; for deeper relationships pass the parent's ID as a filter. The details of putting the version in the path (/v1) are in our API versioning guide.
Which HTTP Method Should You Use and When?
The method tells the client whether an operation is safe and repeatable, and that decides retry behavior. Safe means it does not change state; idempotent means doing the same request once or ten times leaves the same result.
| Method | What it does | Safe | Idempotent | Example |
|---|---|---|---|---|
| GET | Reads | Yes | Yes | GET /v1/orders/7 |
| POST | Creates or starts an action | No | No (yes with a key) | POST /v1/orders |
| PUT | Replaces a resource entirely | No | Yes | PUT /v1/dealers/B-204/addresses/3 |
| PATCH | Updates partially | No | Depends on design | PATCH /v1/orders/7 |
| DELETE | Deletes | No | Yes | DELETE /v1/orders/7 |
A successful POST returns 201 with the new resource's address in the Location header; a long-running operation returns 202. GET never changes data, otherwise caches and retry mechanisms produce surprises. In PATCH, a relative instruction like "increase quantity by 3" is not idempotent, while an absolute one like "set quantity to 10" is; carry absolute values where you can.
How Do You Do Filtering and Sorting on List Endpoints?
Filtering and sorting go in the query string with explicitly defined fields. Example: GET /v1/orders?status=pending&dealer_id=B-204&created_from=2026-12-01&sort=-created&limit=50.
- Allow-list of fields: An unknown filter is not silently ignored but rejected with 400; otherwise a typo makes every record come back.
- Consistent format: A
_fromand_topair for ranges; a leading minus for descending sort. - Page size cap: Default 25, maximum 100; the cap is documented.
- Index reality: Six filter fields create 2⁶ = 64 combinations; you cannot index them all. Design indexes for the three or four most common combinations. See our database indexing guide.
Pagination: Should You Use Offset or Cursor?
Offset is fine for small lists; for lists that keep growing and receiving new records, a cursor is both faster and more consistent. The gap grows with the page number.
Say there are 1,000,000 orders and the page size is 100, which makes 10,000 pages. With offset, to serve page 10,000 the database skips 999,900 rows and reads 100, scanning 1,000,000 rows. If we take scan speed as a representative 5,000,000 rows per second and a fixed cost of 2 ms per page, the last page takes 1,000,000 ÷ 5,000,000 = 0.2 s = 200 ms + 2 ms = 202 ms. With a cursor we read what comes after the last record from the index: 100 rows, about 2 ms.
For a client pulling the whole list with offset, the total rows scanned are 100 × (1 + 2 + … + 10,000) = 100 × 10,000 × 10,001 ÷ 2 = 5,000,500,000: 1,000.1 s of scanning + 20 s of fixed cost ≈ 1,020 s (17 minutes). With a cursor it is 1,000,000 rows (0.2 s) + 20 s = 20.2 s. The ratio is 1,020.1 ÷ 20.2 ≈ 50×; rows scanned are about 5,000 times fewer, and the time gap is smaller because of the fixed per-request cost.
The second problem is drift. With the list sorted newest first, if 10 new orders arrive after the client reads page 1, offset page 2 starts with the last 10 records of the old page 1: 10 duplicates in a page of 100, or 10%. A cursor says "after this record", so it does not drift.
- Cursor content: The sort key (
createdandid, which must be unique) is encoded into an opaque, signed string; the client cannot interpret it. - Response shape: An array of records and
next_cursor; on the last page the field is empty. If the filter changes, the old cursor is invalid.
How Do You Design the Error Format and Status Codes?
An error response must be readable by humans and machines and arrive in the same shape from every endpoint. Keep the fields simple:
- code: A stable machine-readable key (
quantity_invalid); it does not change when the message does. - message: A short text saying what happened and how to fix it.
- fields: For validation errors, which field was rejected and why (
items[3].quantity: "must be between 1 and 500"). - request_id: An ID the server assigns to every request; support finds every log line with it.
| Code | When? | What should the client do? |
|---|---|---|
| 400 | Request could not be parsed (broken JSON) | Fix it; retrying is pointless |
| 401 | No or invalid credentials | Obtain new credentials |
| 403 | Credentials valid, no permission | Do not retry |
| 404 | Resource missing or not visible to this client | Check the address |
| 409 | State conflict (cancelling a shipped order) | Read the current state |
| 412 | Precondition failed (ETag differs) | Re-read, then reapply |
| 422 | Format valid, content invalid (quantity 0) | Fix according to the field list |
| 429 | Rate limit exceeded | Wait for Retry-After |
| 503 | Temporary outage | Retry with increasing delay |
Two rules matter: never return 200 on an error, because client libraries and monitoring tools trust the status code; and keep internal details (stack traces, query text) out of the body, sending only request_id. Returning 404 instead of 403 to someone asking for another dealer's order is a common choice to avoid revealing that it exists; for permission rules see our API security guide.
How Does an Idempotency-Key Prevent Duplicate Orders?
A client can resend the same POST, but the server creates the order only once; the way to get there is to mark the request with a unique key. The problem: the server processes the order, the response is lost on the network, the client times out and safely retries; without a key, a second order appears.
Say there are 4,000 order POSTs a day and a 0.5% timeout rate: 4,000 × 0.005 = 20 requests. If the server had already processed 60% of them, 20 × 0.6 = 12 duplicate orders appear. At an average order of ₺8,500 that is 12 × ₺8,500 = ₺102,000 of wrong orders a day. With a key, that number drops to zero.
- The client generates a key: Once per new order intent, an unpredictable value (the
Idempotency-Keyheader); a retry sends the same one. - The server records it: The key and a hash of the body are written in the same transaction as the order; both happen or neither does.
- A repeat returns the first response: The same key creates no new order and returns the same order number. The same key with a different body returns 422; if the first request is still processing, 409.
- Retention is limited: For example 24 hours; 4,000 records × about 1 KB = about 4 MB, so the cost is negligible.
The client retries only idempotent methods or keyed POSTs, with delays that grow like 1, 2, 4 seconds. If two updates collide on the same record, compare the ETag with If-Match; the details are in our concurrency and locking guide.
How Do Batch Endpoints, Field Selection and ETag Reduce Load?
One batch request instead of many small ones, selected fields instead of unneeded ones, and a 304 response for unchanged data cut network and server load substantially.
Batch endpoint. Say a dealer's ERP fetches product details for a 50-line order. One call per line (the N+1 pattern) at 120 ms each means 50 × 120 ms = 6,000 ms = 6 s of waiting. If a single call such as GET /v1/products?code=K1,K2,… returns in 400 ms, the time is 6,000 ÷ 400 = 15 times shorter (−93.3%). A dealer with 300 requests per minute can process 300 ÷ 50 = 6 orders per minute when each needs 50 calls, but 300 with the batch call.
Field selection. If an order record is 4 KB and most screens only need number, status and total, ?fields=id,status,total brings the response down to about 1 KB (−75%). A 100-record list is 100 KB instead of 400 KB; on a 2 Mbps connection 400 KB × 8 = 3,200 kbit ÷ 2,000 kbit/s = 1.6 s versus 0.4 s. At 50,000 list calls a day the saving is 50,000 × 300 KB = 15 GB.
Conditional requests. If a product detail is 4,000 bytes, read 120,000 times a day, and 80% of reads find unchanged data, the server compares If-None-Match with the ETag and returns a 304 of about 300 bytes. Transfer becomes 24,000 × 4,000 + 96,000 × 300 = 96 MB + 28.8 MB = 124.8 MB instead of 120,000 × 4,000 = 480 MB: −74.0%. To cut this load further with a gateway and caching, see our API gateway guide.
REST or GraphQL? A Short Comparison
For public, resource-oriented, cache-friendly partner APIs, REST is usually enough; GraphQL is worth considering when many different screens ask for nested data. They are not rivals but different balance points.
| Topic | REST | GraphQL |
|---|---|---|
| Data shape | Server decides; field selection can be added | Client decides in the query |
| Nested data | A few requests or an expand parameter | One query |
| Caching | HTTP caching and ETag work naturally | Single endpoint; caching designed separately |
| Error reporting | HTTP status code | Often 200 with an error list |
| Cost control | Per-endpoint rate limits are enough | Query depth and complexity limits needed |
| Public partner API | Simple, familiar, wide tool support | Fits if the client team is manageable |
How Do You Carry Out REST API Design in Six Steps?
- List the resources: Pull nouns and operations from use cases: dealer, order, line item, product; create, cancel, list.
- Write the naming and method contract: Plural nouns, spelling convention, date and money format, the method table.
- Write the list contract: Allowed filters, sorting, page size cap, cursor format.
- Write the error and retry contract: Error body, status code table, Idempotency-Key, ETag and If-Match.
- Define and test: A machine-readable definition file, an example request and response per endpoint, contract tests against the definition. For writing the docs, see our API documentation guide.
- Try with a pilot client, then version: Run the real flow with one partner, write the problems back into the contract, then go live.
How Do You Calculate the Payback of Contract Discipline?
Payback comes from duplicate-order cleanup effort, integration time, support load and infrastructure savings. Representative assumptions: 12 dealer clients, an hourly cost of ₺300, investment of 40 person-days × ₺9,000 = ₺360,000.
| Item | Calculation | Monthly gain |
|---|---|---|
| Duplicate order cleanup | 12 duplicates × 22 days = 264 × 20 min = 5,280 min = 88 h × ₺300 | ₺26,400 |
| New client integration | 1 client a month × 8 days × 8 h = 64 h × ₺300 | ₺19,200 |
| Support ticket time | 90 tickets × (25 − 8) min = 1,530 min = 25.5 h × ₺300 | ₺7,650 |
| Infrastructure (cursor, ETag, field selection) | Direct saving | ₺4,000 |
| Gross | ₺57,250 | |
| Contract tests and maintenance | −₺6,000 | |
| Net | ₺51,250 |
Payback: ₺360,000 ÷ ₺51,250 ≈ 7.0 months. If the gains halve, gross is ₺28,625, net ₺22,625, and the time rises to 360,000 ÷ 22,625 ≈ 15.9 months. Recalculate with your own client count and hourly cost.
We recommend reading: How to manage API keys, quotas and usage plans
We recommend reading: What is a webhook? Event notification, security and retry guide
We recommend reading: What is B2B e-commerce? Dealer portal and order flow guide
Integration and API Design with İnovabil
At İnovabil our focus is building firm-specific software from scratch: custom software, ERP, CRM, e-commerce, web, mobile and integration. When you need an API that exposes your systems or connects them to outside systems, we recommend writing the endpoint contract down during requirements and design, so disputes with the client side get settled before any code is written.
We built CRM, purchasing and mobile for Avcılar İnşaat; a purchasing system for İZBAN; logistics and shipment planning with wholesale order management for Karyak; warehouse management and a complaint and support management system for Sleepy; and a prepaid cargo system for Kredili Kargo. The numeric examples in this article are representative and not any customer's measurement. Briefly describe your integration need and we will draft the contract together.
We recommend reading: Our software development process: from analysis to launch
Frequently Asked Questions
What is REST API design and what should you watch for?
It is the work of exposing a system's data and operations as resources over HTTP with consistent rules for addresses, methods, responses and errors. Plural nouns, methods used for their meaning, cursor pagination, a machine-readable error format and safe retries are the main topics.
What is the difference between offset and cursor pagination?
Offset skips a number of records and reads what follows; the rows scanned grow with the page number and pages drift when new records arrive. A cursor reads what comes after the last record from an index; cost stays flat and there is no drift. In the example the last page takes 202 ms against about 2 ms.
What does an Idempotency-Key do?
It makes the server perform an operation once even if the client resends the same POST, so a retry after a network timeout becomes safe. In the example, 12 duplicate orders a day, or ₺102,000 of wrong orders, drop to zero with a key.
Which fields should an error response contain?
A machine-readable code, a short message, a field list for validation errors and a request ID assigned to every request. The status code must be right; do not return 200 on an error and keep internal details out of the body.
Should I choose REST or GraphQL?
For public, resource-oriented, cache-friendly partner APIs REST is usually enough and simpler. GraphQL can be considered for internal use where many different screens ask for nested data. For most businesses, starting with REST is the lower-risk path.