---
title: "Drupal JSON-API Params (DJAP) | Factorial"
meta:
  description: "This post is for JavaScript developers working on a decoupled site using Drupal CMS’s JSON-API. I as the maintainer of the drupal-jsonapi-params (DJAP2 for short) want to demonstrate how the library solves code readability issues and vastly improves developer experience."
  keywords: "Drupal Blog"
  "og:description": "This post is for JavaScript developers working on a decoupled site using Drupal CMS’s JSON-API. I as the maintainer of the drupal-jsonapi-params (DJAP2 for short) want to demonstrate how the library solves code readability issues and vastly improves developer experience."
  "og:title": "Drupal JSON-API Params (DJAP) | Factorial"
  "twitter:description": "This post is for JavaScript developers working on a decoupled site using Drupal CMS’s JSON-API. I as the maintainer of the drupal-jsonapi-params (DJAP2 for short) want to demonstrate how the library solves code readability issues and vastly improves developer experience."
  "twitter:title": "Drupal JSON-API Params (DJAP) | Factorial"
---

November 23, 2022

# Drupal JSON-API Params (DJAP)

This post is for JavaScript developers working on a decoupled site using Drupal CMS’s JSON-API. I would demonstrate how we can use drupal-jsonapi-params (also known as DJAP for short, a JavaScript library) to improve code readability and improve developer experience.

**DISCLAIMER** I am the maintainer of  [drupal-jsonapi-params](https://www.npmjs.com/package/drupal-jsonapi-params) (DJAP for short). DJAP stands for “drupal-jsonapi-params” coined by Stuart Clark aka Deciphered, the creator of  [Druxtjs](https://druxtjs.org/) (Nuxt + Drupal) project. Now, let’s talk about how DJAP can help JavaScript developers working on a decoupled site using Drupal CMS’s JSON-API.

## Background

When fetching information from a Drupal backend, we quite often have to use some filters. The  [documentation page on Drupal.org](https://www.drupal.org/docs/core-modules-and-themes/core-modules/jsonapi-module/filtering) provides an excellent guide on how to achieve this.

Example A: To get node articles that are promoted or sticky and created by admin,  
 You would come up with a query parameter as follows:

```

```

Breaking the above query down for clarity:

```

```

Assuming we use Axios in our project, a fetch would look something like the below:

```

```

## Problem

If you search for a problem, then you will have it. I joined a project with loads of similar queries splattered across the codebase. 

> It was difficult for me to understand the intent of the Developer from the query  
>  \~ Developer who takes over the project (or me in the future)

While fixing a bug in such a query, instead of finding the bug, it was easier for me to re-write the whole thing.

> It’s a pain to comprehend what is going on in the merge request I’ve to review. All I see is a fetch request and a lot of letters.  
>  \~ Developer who reviews the code

Now, we at Factorial go through the Four eyes principle of approving a Merge Request. The Four eyes principle is a requirement that two individuals approve some action before it can be taken. The Four eyes principle is sometimes called the two-man rule or the two-person rule.

However, the changes in query parameters in a merge request are hard to decipher. 

> Adding comments to explain what is going on, helps, although I wish I could be more granular.  
>  \~ Developer who writes the code

You can add detailed comments for such queries to help your future self or another developer. Please do so.

## Solution

Use a library to generate the query. JSON-API is not a Drupal-specific API. There are loads of libraries available to create the filter query. Depending on your taste, you may find the appropriate client implementation [over here](https://jsonapi.org/implementations/).

We choose to go with the  [drupal-jsonapi-params](https://www.npmjs.com/package/drupal-jsonapi-params) library. 

So our Example A, using “drupal-jsonapi-params” (DJAP for short) would

```

```

We can also have **granular** comments to enhance readability:

```

```

**As you can see, the library solves code readability issues and vastly improves developer experience.**

For more details about available methods, please check the  [documentation on the Project Page](https://www.npmjs.com/package/drupal-jsonapi-params).

## Closing Words

Drupal JSON-API Params is an open-source project. Please spread awareness if you like an open-source project by sharing it with others. If you are using the project and would recommend it to others, please consider starring the project on  [GitHub](https://github.com/d34dman/drupal-jsonapi-params) and on other platforms like  [Drupal.org](https://www.drupal.org/project/drupal_jsonapi_params).

![Shibin Blog author](https://bo.factorial.io/sites/default/files/styles/contact_card__small__1x/public/2021-05/picture-751698-1409022901-2.jpg?h=a2f616d4&itok=aAPLogpg)

Shibin Das

Senior Backend Developer  
[Profile on Drupal.org](https://www.drupal.org/u/d34dman)

[shibin@factorial.io](mailto:shibin@factorial.io)

## Related articles

[Drupal JSON-API Params (DJAP)](https://www.factorial.io/en/blog/drupal-json-api-params-djap)November 24, 2022

![Illustration with the words Drupal, CSS, HTML, and JS](https://bo.factorial.io/sites/default/files/styles/teaser_card__small__1x/public/2025-04/Hero_Drupal_Agency.jpg?h=9553d40f&itok=MF10VZcD)

[Visiting DrupalCon Prague 2022](https://www.factorial.io/en/blog/visiting-drupalcon-prague-2022)October 4, 2022

![Image showing the Factorial team at DrupalCon Prague 2022, holding the Lille rooster mascot.](https://bo.factorial.io/sites/default/files/styles/teaser_card__small__1x/public/2022-11/Factorial-blog-Ddrupalcon-prague-2022-square.png?h=a4f6488c&itok=qruDraqm)

[New dates for the Drupal User Group Hamburg](https://www.factorial.io/en/blog/drupal-user-group-hamburg)October 20, 2022

![Logo of the Drupal User Group Hamburg](https://bo.factorial.io/sites/default/files/styles/teaser_card__small__1x/public/2022-10/factorial-blog-drupal-user-group-hamburg-square.png?h=60a9e832&itok=UixizXq9)