5 Modeling data
This chapter covers
- Designing resource data models
- Designing operations data from resource models
- Spotting missing capabilities with data
- Completing business errors
- Ensuring a versatile API that meets consumer needs
After giving an HTTP representation to operations and locating coarse-grained input and output data in HTTP requests and responses, such as “Product information” in the response body of “Read a product,” we can model the data. This implies deciding that a product is an object with a required product reference (integer), category (string), price (float), and optional keywords (array of strings). Additionally, the “Product reference” path parameter will be an integer, and we will break down the “Filters” of “Search for products” into “category” and “keywords.”
Data modeling involves selecting data, names, types, and organizations in objects or arrays, which can be error-prone. It’s easy to end with incomplete and inconsistent input and output models. It can also be laborious, especially when wasting time in arguments such as available
versus isAvailable
at the wrong moment. Our goal is to efficiently model versatile data that meets consumer needs. Although this is a good first draft, we will refine our design later to avoid managing too many concerns at once; user-friendliness, security, performance, and implementation constraints are crucial in data modeling and will be addressed in later chapters.