Formats Supported By the API Platform

Yusuf Biberoğlu
The Startup
Published in
6 min readSep 8, 2020

The API system has built-in content negotiation capabilities. By default, only the JSON-LD format is enabled. However, API Platform Core supports many more formats and can be extended.

Available formats are: JSON-LD, GraphQL, JSON, JSON:API, HAL, XML, YAML, CSV, HTML (API docs).

1. JSON-LD

Data is messy and disconnected. JSON-LD organizes and connects it, creating a better Web.

JSON-LD is a lightweight Linked Data format. It is easy for humans to read and write. It is based on the already successful JSON format and provides a way to help JSON data interoperate at Web-scale. JSON-LD is an ideal data format for programming environments, REST Web services, and unstructured databases such as Apache CouchDB and MongoDB.

Example;

{
"@context": "https://json-ld.org/contexts/person.jsonld",
"@id": "http://dbpedia.org/resource/John_Lennon",
"name": "John Lennon",
"born": "1940-10-09",
"spouse": "http://dbpedia.org/resource/Cynthia_Lennon"
}

Linked Data empowers people that publish and use information on the Web. It is a way to create a network of standards-based, machine-readable data across Web sites. It allows an application to start at one piece of Linked Data, and follow embedded links to other pieces of Linked Data that are hosted on different sites across the Web.

2. GraphQL

A query language for your API

GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools.

3. JSON

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language Standard ECMA-262 3rd Edition — December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.

JSON is built on two structures:

  • A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.
  • An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.

These are universal data structures. Virtually all modern programming languages support them in one form or another. It makes sense that a data format that is interchangeable with programming languages also be based on these structures.

4. JSON API

A SPECIFICATION FOR BUILDING APIS IN JSON

JSON API is a format that works with HTTP. It delineates how clients should request or edit data from a server, and how the server should respond to said requests. A main goal of the specification is to optimize HTTP requests; both in terms of the number of requests and the size of data packages exchanged between clients and servers. JSON API module exposes an implementation for data stores and data structures, such as entity types, bundles, and fields.

5. HAL — Hypertext Application Language

HAL is a simple format that gives a consistent and easy way to hyperlink between resources in your API.

Adopting HAL will make your API explorable, and its documentation easily discoverable from within the API itself. In short, it will make your API easier to work with and therefore more attractive to client developers.

APIs that adopt HAL can be easily served and consumed using open source libraries available for most major programming languages. It’s also simple enough that you can just deal with it as you would any other JSON.

HAL provides a set of conventions for expressing hyperlinks in either JSON or XML.

Instead of using ad-hoc structures, or spending valuable time designing your own format; you can adopt HAL’s conventions and focus on building and documenting the data and transitions that make up your API.

HAL is a little bit like HTML for machines, in that it is generic and designed to drive many different types of application via hyperlinks. The difference is that HTML has features for helping ‘human actors’ move through a web application to achieve their goals, whereas HAL is intended for helping ‘automated actors’ move through a web API to achieve their goals.

Having said that, HAL is actually very human-friendly too. Its conventions make the documentation for an API discoverable from the API messages themselves. This makes it possible for developers to jump straight into a HAL-based API and explore its capabilities, without the cognitive overhead of having to map some out-of-band documentation onto their journey.

6. Extensible Markup Language (XML)

Extensible Markup Language (XML) is a simple, very flexible text format derived from SGML (ISO 8879). Originally designed to meet the challenges of large-scale electronic publishing, XML is also playing an increasingly important role in the exchange of a wide variety of data on the Web and elsewhere.

  • XML stands for eXtensible Markup Language
  • XML is a markup language much like HTML
  • XML was designed to store and transport data
  • XML was designed to be self-descriptive

7. YAML: YAML Ain't Markup Language

YAML is a human friendly data serialization standard for all programming languages. It is commonly used for configuration files and in applications where data is being stored or transmitted.

8. Comma-Separated Values (CSV) Files

The comma separated values format (CSV) has been used for exchanging
and converting data between various spreadsheet programs for quite
some time. Surprisingly, while this format is very common, it has
never been formally documented. Additionally, while the IANA MIME
registration tree includes a registration for "text/tab-separated-values" type, no MIME types have ever been registered with IANA for CSV. At the same time, various programs and operating systems have begun to use different MIME types for this format.

9. HTML (API docs)

HTML stands for Hyper Text Markup Language

— — —

My YouTube Channel;

https://www.youtube.com/@yusufbiberoglu

https://yusufbiberoglu.com/

mail@yusufbiberoglu.com

My Udemy Course;

Symfony application using Google OAuth for authentication. When a user signs in through Google, our system will check if the user already exists in our database. If not, it will create a new user account. Once authenticated, either as a new or existing user, our application will generate a JSON Web Token (JWT). Built on the API Platform.

If you want a detailed explanation, please purchase my Udemy course.

https://www.udemy.com/course/google-oauth-php-symfony-api-platform-jwt/?referralCode=67A58BBAE3151CDC1255

Discount Coupon: AD25A625CB8976085C88

Here’s my articles which might interest you;

Learn How Computer Works and What is Binary in 2 minutes

JWT Authentication and Refresh Token to API Platform

Symfony Search Engine with Elasticsearch

Testing Benford’s Law in Symfony 5, Php Framework

--

--