Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

You are designing endpoints for an order system in Spring MVC. A colleague proposes POST /createOrder, GET /getOrder?id=5 and POST /cancelOrder?id=5. How would you model these as REST resources, and which HTTP methods and status codes would you use?

I would model nouns as resources, /orders and /orders/{id}, and let the HTTP method carry the verb. POST /orders creates an order and returns 201 Created with a Location header pointing to /orders/{id}; GET /orders/{id} returns 200, or 404 when the order does not exist. Cancelling can be a state change with PATCH /orders/{id} setting the status, or an action sub-resource such as POST /orders/{id}/cancellation; both are defensible if used consistently. For errors, 400 covers invalid input, 409 a state conflict such as cancelling a shipped order, and 422 is fine if the team standard uses it for validation.

Why this question is asked

Endpoint names like /createOrder are what most of us write first, because they read like method calls. They work, but they throw away what HTTP already gives us: standard methods with known meanings, status codes clients and proxies understand, and caching and retry rules that tools rely on. Interviewers ask this question to see whether we can turn a call-style design into a resource design and choose status codes deliberately. In this answer, we will recap the resource idea, redesign the three endpoints, look at cancellation in both styles, choose status codes for errors, and answer the follow-ups about action resources and repeated deletes.

1A Quick Recap of Resources and Methods

In REST, a resource is a thing the API exposes, named with a noun and identified by a URI: the collection of orders at /orders, and one order at /orders/5. The HTTP method says what we want to do with it. GET reads and must not change anything, so it is safe to repeat and can be cached. POST creates something new in a collection or triggers processing. PUT replaces a resource completely, PATCH changes part of it, and DELETE removes it. PUT and DELETE are idempotent, meaning that sending the same request twice leaves the server in the same state as sending it once.

The colleague's design puts the verb in the path and uses POST for a read and a query parameter for the identity. That hides the meaning from HTTP: a proxy cannot cache GET /getOrder safely without knowing it is a read, and a client library cannot know that POST /cancelOrder is safe to retry.

2Redesigning the Three Endpoints

Mapped to resources, creating becomes POST on the collection, reading becomes GET on the item, and the identity moves into the path.

Java
@RestController
@RequestMapping("/orders")
class OrderController {
@PostMapping // was POST /createOrder
ResponseEntity<OrderResponse> create(@Valid @RequestBody CreateOrderRequest req) {
OrderResponse created = service.create(req);
URI location = ServletUriComponentsBuilder.fromCurrentRequest()
.path("/{id}").buildAndExpand(created.id()).toUri();
return ResponseEntity.created(location).body(created); // 201, Location: /orders/5
}
@GetMapping("/{id}") // was GET /getOrder?id=5
ResponseEntity<OrderResponse> get(@PathVariable long id) {
return service.find(id)
.map(ResponseEntity::ok) // 200 with the order
.orElse(ResponseEntity.notFound().build()); // 404 when it does not exist
}
}
From call-style endpoints to resources
Colleague's endpointResource designSuccess status
POST /createOrderPOST /orders201 Created, Location: /orders/{id}
GET /getOrder?id=5GET /orders/5200 OK, or 404 Not Found
POST /cancelOrder?id=5PATCH /orders/5 or POST /orders/5/cancellation200 OK or 201 Created

Notice what 201 and Location give the client: confirmation that something new exists and the address where it lives, so the client does not have to build URLs itself. Returning the created order in the body as well saves a second request.

3Cancelling: State Change or Action Resource

Cancellation is the interesting one, because it is a business action rather than a plain edit. There are two common designs. The first treats it as a state change of the order: PATCH /orders/5 with a body that sets the status to CANCELLED. It is simple and needs no new URI, and it fits when cancelling really is just a field changing value.

Java
PATCH /orders/5
Content-Type: application/merge-patch+json
{"status": "CANCELLED"}
-> 200 OK {"id":5,"status":"CANCELLED",...}
POST /orders/5/cancellation
Content-Type: application/json
{"reason": "customer request"}
-> 201 Created Location: /orders/5/cancellation
{"orderId":5,"reason":"customer request","refundId":"r-881","cancelledAt":"2026-11-05T10:00:00Z"}

The second treats the cancellation itself as a resource: POST /orders/5/cancellation creates a cancellation, which can have its own data such as a reason, a refund reference and a timestamp, and can be read later with GET. It fits when cancelling triggers a process, needs its own input, or must be audited. Both are defensible; what matters is that the API uses one style consistently for similar actions, so clients can guess the shape of the next one.

4Choosing Status Codes for Errors

Error codes tell the client what kind of mistake happened and whether retrying can help. 400 Bad Request means the request itself is invalid: malformed JSON, a missing required field, a negative quantity. 404 Not Found means the order does not exist. 409 Conflict means the request is valid but clashes with the current state of the resource, such as cancelling an order that has already shipped; the client cannot fix it by resending, only by changing its plan. Some teams use 422 Unprocessable Content for validation errors, keeping 400 for malformed syntax; that is fine if the team standard says so and every service follows it.

Java
// Cancelling a shipped order
// HTTP/1.1 409 Conflict
// Content-Type: application/problem+json
{
"type": "https://api.example.com/problems/order-not-cancellable",
"title": "Order cannot be cancelled",
"status": 409,
"detail": "Order 5 has already shipped",
"errorCode": "ORDER_ALREADY_SHIPPED"
}
Step throughChoosing the status for POST /orders/5/cancellation
  1. Is the request body valid?
    YesContinueNo400 (or 422 by team standard)
  2. Does order 5 exist?
    YesContinueNo404 Not Found
  3. Can it still be cancelled?Not shipped, not already cancelled
    Yes201 Created with LocationNo409 Conflict
  4. Return a problem detail for errorsSame shape everywhere

4 steps in order. Play them, or step through them one at a time.

Each check maps to one status, so clients know whether to fix the request, give up, or rethink.

5Repeated Deletes and Idempotency

The second follow-up is about DELETE /orders/{id} when the order is already gone. DELETE is idempotent, but idempotency is about the state of the server, not the response code. After one or two identical DELETE requests the order is deleted either way, so both answers are correct by HTTP: return 204 No Content again, which makes client retries trivially safe, or return 404 Not Found, which tells the client truthfully that nothing was there. Many teams choose 204 for simplicity of retries, others 404 for honesty; again the important part is to pick one and document it. In an order system, real deletion is often replaced by cancellation or archiving anyway, because orders have legal and accounting history.

6Follow-up questions

When is an action-style sub-resource better than a PATCH of a status field?

When the action is more than a field change: it needs its own input such as a reason, starts a process such as a refund, has its own result the client may want to read later, or has rules that differ from ordinary edits. Then POST /orders/5/cancellation makes the action explicit, easy to authorise separately and easy to audit. If cancelling really is just setting a status with no side effects, PATCH is simpler.

What should DELETE /orders/{id} return when the order was already deleted?

Either 204 or 404 is correct, because idempotency means the server state is the same after repeated requests, not that the response is identical. I would usually return 204 so retries after a timeout look successful, or 404 if the team prefers to report that nothing was found. The choice should be in the API guidelines and the same across services.

Should POST /orders be idempotent?

POST is not idempotent by definition, so a retry after a timeout can create a duplicate order. A common solution is an Idempotency-Key header: the client sends a unique key with the request, and the server stores the result per key and returns the same 201 response for a repeated key instead of creating a second order.

7Conclusion

In this answer, we turned call-style endpoints into resources: POST /orders returning 201 with a Location header, GET /orders/{id} returning 200 or 404, and cancellation either as PATCH of the status or as POST /orders/{id}/cancellation, used consistently. We chose 400 for invalid input, 409 for state conflicts such as cancelling a shipped order, 422 only if the team standard uses it, and saw that a repeated DELETE may answer 204 or 404 as long as the choice is documented.

What to say in the interviewAbout 90 seconds aloud

Open with

I would model the order as a resource and let the HTTP method carry the verb, instead of putting verbs in the path. So the collection is /orders and one order is /orders/{id}.

Then, if they want more

Creating becomes POST /orders, which returns 201 Created with a Location header pointing to /orders/5 and the created order in the body. Reading becomes GET /orders/5, returning 200, or 404 if the order does not exist, and because it is a GET it is safe, cacheable and retryable, which POST /getOrder was not.

Cancelling is a business action, and I see two good options. If it is really just a status change, PATCH /orders/5 with status CANCELLED. If it needs a reason, triggers a refund or must be audited, I make it a sub-resource, POST /orders/5/cancellation, returning 201. Both are defensible; I would pick one style and use it for every similar action.

For errors: 400 for invalid input, 404 for an unknown order, and 409 Conflict when the request is valid but the state forbids it, like cancelling an order that has already shipped. If the team standard uses 422 for validation, that is fine too, as long as all services agree, ideally with problem details bodies.

And for a repeated DELETE, both 204 and 404 are correct, since idempotency is about server state.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "You are designing endpoints for an order system in Spring MVC. A colleague proposes POST...": https://scrivio-interview-library.netlify.app/spring-boot/rest-api-design/caca220d2b/