JSON adapter for Integreat
Adapter that lets
Integreat parse and stringify JSON.

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 },
})
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 },
})
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.