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.

5.1 An overview of data modeling

5.1.1 Which data are we modeling?

5.1.2 Introducing the JSON portable data format

5.1.3 Modeling data

5.2 Designing theoretical resource data models

5.2.1 Determining a resource’s structure

5.2.2 Choosing an object resource’s properties

5.2.3 Choosing a property name and type

5.2.4 Indicating required properties

5.2.5 Listing and modeling properties efficiently

5.3 Designing inputs and outputs data models

5.3.1 Designing a read operation’s inputs and success outputs

5.3.2 Designing a search operation’s inputs and success outputs

5.3.3 Designing a create operation’s inputs and success outputs

5.3.4 Designing an update operation’s inputs and success outputs

5.3.5 Designing a delete operation’s inputs and success outputs

5.3.6 Designing a temporary error data model

5.4 Streamlining input and output data modeling