JSON adapter for Integreat
npm install integreat-adapter-jsonAdapter that lets
Integreat parse and stringify JSON.


Requires node v18 and Integreat v1.0.
Install from npm:
```
npm install integreat-adapter-json
Example of use:
`javascript
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:
`javascript`
{
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 unlessincludeHeaders
you set the option to false (it's true by default). Headers'Content-Type'
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 .
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:
`javascript
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.
The tests can be run with npm test`.
Please read
CONTRIBUTING
for details on our code of conduct, and the process for submitting pull
requests.
This project is licensed under the ISC License - see the
LICENSE
file for details.