← All writing

API design is not a convention problem, it’s a fundamental problem

I’ve written bad APIs before, and I’ve seen many experienced developers do the same. Memorizing conventions is easy. Applying them consistently in real APIs is rare. Here’s why:

  1. Lack of principles. Many developers know OOP/DDD terms but can’t apply them.
  2. No separation of concerns: Too many times I saw business logic leaking into API endpoints, that’s not abstraction, that’s more like implementation details.
  3. Ignorance to conventions: Many devs do not care about conventions at all. They are proud and happy to use their own “unique ways”.
  4. Problem-solving disguised as APIs: Your endpoints should not look like functions/methods you use internally, they should reflect the user’s perspective.

Here’s the difference. The first endpoint is a method call wearing an HTTP costume, it tells you how the server is built. The second one reads like the user’s question: show me this user’s shipped orders. Anyone on the team can guess the next endpoint without asking you.

POST /api/getOrdersByUserAndStatus
Content-Type: application/json
{ "userId": 42, "status": "shipped" }
GET /api/users/42/orders?status=shipped

How to fix it:

  1. Understand and internalize OOP and DDD, maybe some design patterns too along the way, it will help you in the long run.
  2. Always move your business logic into services, understand abstraction, apply abstraction multiple times.
  3. Your teammates do not want to understand your “unique ways”, stick to conventions, they will thank you.
  4. The best endpoint is the endpoint that receives no parameters, minimize the number of parameters.
  5. Accept payloads that are naturally generated on the frontend, process it on the server if you must, but never tell your frontend to preprocess payloads.

Moving business logic into services looks like this. The endpoint only translates HTTP into a call and the result back into a status code. The service owns the rule. If you can’t test a business rule without faking an HTTP request, it’s in the wrong place.

Program.cs
// The rule lives in the endpoint
app.MapPost("/orders/{id}/cancel", async (int id, AppDb db) =>
{
var order = await db.Orders.FindAsync(id);
if (order is null) return Results.NotFound();
if (order.Status == OrderStatus.Shipped) return Results.Conflict("Already shipped");
order.Status = OrderStatus.Cancelled;
await db.SaveChangesAsync();
return Results.NoContent();
});
Program.cs
// The endpoint translates, the service decides
app.MapPost("/orders/{id}/cancel", async (int id, OrderService orders) =>
(await orders.Cancel(id)) switch
{
CancelResult.NotFound => Results.NotFound(),
CancelResult.AlreadyShipped => Results.Conflict("Already shipped"),
_ => Results.NoContent(),
});

Clean APIs should solve problems, not create them.