Identifying Resources from Domain Models
What you'll learn: How to systematically extract REST resources from your domain model by identifying the core entities your API should expose.
When designing a REST API, you don't start from scratch—you start with your domain model, the business entities and concepts that already exist in your system. The key is recognizing which of these domain entities should become resources in your API.
The Domain Model as Your Blueprint
Think of your domain model like the floor plan of a house. Not every detail in the plan becomes a doorway to the outside world. Similarly, not every internal business object needs to be a resource exposed by your REST API. Your job is to identify which entities clients need to interact with directly.
Spotting Resource Candidates
Look for:
- Core business entities (User, Order, Product, Invoice)
- Collections that group those entities (list of Users, list of Orders)
- Relationships that clients need to navigate (an Order's LineItems)
- Domain concepts clients need to query or manipulate (ShoppingCart, CustomerProfile)
For example, if you're building an e-commerce system, your domain might include Customer, Product, Order, and Payment. Each of these likely becomes a resource. An internal helper class like TaxCalculator probably doesn't—it's implementation detail, not something clients interact with directly.
Focus on the Client's Perspective
Ask: "What would a client application need to read, create, update, or delete?" If a client never directly manipulates something, it might not need its own resource endpoint. For instance, an OrderTotal might just be a field within an Order resource rather than a separate resource itself.
Key Takeaway: Identify REST resources by examining your domain model and selecting the business entities and concepts that clients need to interact with—focus on nouns that represent meaningful things in your problem domain, not implementation details.