integreat-adapter-json

1.0.1 • Public • Published

JSON adapter for Integreat

Adapter that lets Integreat send and receive content in JSON.

npm Version Maintainability

Getting started

Prerequisits

Requires node v18 and Integreat v1.0.

Installing and using

Install from npm:

npm install integreat-adapter-json

Example of use:

import integreat from 'integreat'
import httpTransporter from 'integreat-transporter-http'
import jsonAdapter from 'integreat-adapter-json'
import defs from './config.js'

const great = Integreat.create(defs, {
  transporters: { http: httpTransporter },
  adapters: { json: jsonAdapter },
})

// ... and then dispatch actions as usual

Example service configuration:

{
  id: 'store',
  transporter: 'http',
  adapters: ['json'],
  options: {
    includeHeaders: true
  },
  endpoints: [
    { options: { uri: 'https://api.com/jsonApi' } }
  ]
}

Data headers for sending with content-type application/json will be set unless you set the includeHeaders option to false (it's true by default). Headers will be set where there is data, unless a content-type header is already set. The case of the header will always be changed to 'Content-Type'.

JSON transformer

The package also includes a transformer, that works exactly like the adapter, except it is intended for use in mutation pipelines with { $transform: 'json' }. You may use it like this:

Example of use:

import integreat from 'integreat'
import httpTransporter from 'integreat-transporter-http'
import jsonTransformer from 'integreat-adapter-json/transformer.js'
import defs from './config.js'

const great = Integreat.create(defs, {
  transporters: { http: httpTransporter },
  transformers: { json: jsonTransformer },
})

// In a mutation pipeline:

const mutation = ['response.data', { $transform: 'json' }]

The includeHeaders option from the adapter, does not apply to the transformer.

Running the tests

The tests can be run with npm test.

Contributing

Please read CONTRIBUTING for details on our code of conduct, and the process for submitting pull requests.

License

This project is licensed under the ISC License - see the LICENSE file for details.

Readme

Keywords

Package Sidebar

Install

npm i integreat-adapter-json

Weekly Downloads

6

Version

1.0.1

License

ISC

Unpacked Size

19 kB

Total Files

19

Last publish

Collaborators

  • kjellmorten