5 Data types and defaults

 

This chapter covers

  • What we mean by data types
  • How a null value differs from one that’s missing entirely
  • An exploration of the various primitive and collective data types
  • How to handle serialization for various data types

When designing any API, we always have to think of the types of data we want to accept as input, understand, and potentially store. Sometimes this sounds pretty straightforward: a field called “name” might just be a string of characters. Hidden in this question though is a world of complexity. For example, how should the string of characters be represented as bytes (it turns out there are lots of options for this)? What happens if the name is omitted in an API call? Is that any different from providing an empty name (e.g., { "name": "" })? In this chapter we’ll explore the various data types you will almost certainly experience when designing or using APIs, how best to understand their underlying data representation, and how best to handle the default values of the various types in a sane and straightforward way.

5.1 Introduction to data types

5.1.1 Missing vs. null

5.2 Booleans

5.3 Numbers

5.3.1 Bounds

5.3.2 Default values

5.3.3 Serialization

5.4 Strings

5.4.1 Bounds

5.4.2 Default values

5.4.3 Serialization

5.5 Enumerations

5.6 Lists

5.6.1 Atomicity

5.6.2 Bounds

5.6.3 Default values

5.7 Maps

5.7.1 Bounds