Textual Data Formats

Let's learn about the common encoding styles used in modern API architectures.

Introduction

Web APIs communicate over the network, and therefore, data needs to be serialized before being transmitted onto the network. The following diagram shows the typical data encoding workflow of a server sending its response to the remote client and vice versa.

Press + to interact
Data serialization in API communication
Data serialization in API communication

We can serialize data using serialization methods provided by a language, such as Marshal in Ruby, pickle in Python, Serializable in Java, and so on. External libraries can also be used for this purpose, but they have some common problems. They are language-specific and can tight-couple APIs to that language. Furthermore, these methods lack efficient version control mechanisms and are generally inefficient regarding CPU utilization and encoded data size. Therefore, developers prefer using standardized encoding formats—such as XML, JSON, Protobuf, Avro, and so on—instead of built-in encoding methods.

Textual representation formats

JSON, XML, and CSV are data representation formats that use Unicode characters (text) and support encoding in many languages. The most popular way clients interact with web APIs is by serializing data into XML and JSON formats. CSV is less powerful than XML and JSON because it doesn’t support the data hierarchy and is commonly used when dealing with data in tabular form. These structures have a standardized encoding style, and clients can easily extract and consume data by deserializing it into their respective languages. Text-based representation formats have the following common characteristics:

  • Schemaless structure: Data-related information (metadata) is embedded within the format structure.

  • Machine-readable: The data is well structured and can be easily interpreted by machines.

  • Human-readable: Data is represented in Unicode characters that humans can read and understand.

  • Object representation: ...