djq

d8-jsonapi-querystring

Npm module to create a Drupal 8 JSON-API query string from a nested object.

Showing:

Popularity

Downloads/wk

33

GitHub Stars

7

Maintenance

Last Commit

4yrs ago

Contributors

2

Package

Dependencies

0

Size (min+gzip)

0.3KB

License

ISC

Type Definitions

Built-In

Tree-Shakeable

No?

Categories

Readme

Drupal 8 JSON API query string builder

Create a Drupal 8 JSON API query string from a nested object.

This make it easier to request a Drupal 8 JSON-API site with JSON API module

If you are looking for a complete JS Client for an API-first Drupal 8, you might be interested in waterwheel.js, as it supports JSON API and more.

You may be interested to use it thoses packages in combination with jsonapi-parse to format json responses in a more intuitive way (it resolves nicely included keys and relationships )

USAGE

To create the following query string :

sort[sortCreated][path]=created&sort[sortCreated][direction]=DESC&fields[recipes]=title&include=tags,image&filter[categoryName][condition][path]=category.name&filter[categoryName][condition][value]=Main%20course&page[offset]=0&page[limit]=4

write:

const buildQueryString = require('d8-jsonapi-querystring').buildQueryString

buildQueryString({
  sort: {
    sortCreated: {
      path: 'created',
      direction: 'DESC'
    }
  },
  fields: {
    recipes: ['title']
  },
  include: ['tags', 'image'],
  filter: {
    categoryName: {
      condition: {
        path: 'category.name',
        value: "Main course"
      }
    },
  },
  page: {
    offset: 0,
    limit: 4
  }
})

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100