5 Data types and defaults
This chapter covers...
- What do we mean by data types?
- How does a "null" value differ from one that's missing entirely?
- An exploration of the various primitive and collective data types (e.g., strings, numbers, lists, maps, etc)
- 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 straight forward: 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 field 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 straight-forward way.