Skip to content

willhowlett/parse-drupal-facet-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Parse Drupal Facet API

About

If you happen to want to query a Drupal facets API (https://www.drupal.org/project/facetapi) endpoint using axios or similar you may find the parameters it requires need some tweaking first

The format expected by Facets API endpoints is this

?f[0]=param1:value1&f[1]=param2:value2

If you have an object of parameters you want to pass to it that looks like this

{
  param1: 'value1',
  param2: 'value2'
}

it would need to be converted to this

{
  'f[0]': 'param1:value1',
  'f[1]': 'param2:value2'
}

That's what this helper does.

Usage (with axios example)

import axios from 'axios';
import parseDrupalFacetApi from 'parse-drupal-facet-api';

let params = {
  param1: 'value1',
  param2: 'value2'
}

axios.get('/api', {
    params: parseDrupalFacetApi.convert(params)
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });

If you need to pass multiple values as the same parameter you can do so by passing them as an array, e.g.

  param1: 'value1',
  param2: ['value2a', 'value2b', 'value2c'],
  param3: 'value3'

This will output

  'f[0]': 'param1:value1',
  'f[1]': 'param2:value2a'
  'f[2]': 'param2:value2b'
  'f[3]': 'param2:value2c'
  'f[4]': 'param3:value3'

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published