README
JSONAPI translater for EZContent
This is JSONAPI formatter for EZContent (Drupal distribution). This library is specially designed to work with EZContent only, it deserilize the exposed JSONAPI from EZContent and alter the response to make it digestible for its different frontends.
Install
npm i ezcontent_jsonapi
What it does
- Manage Oauth
- Resolve Drupal content aliases (eg: node/nid, article/article-title etc)
- Combine and alter different components data into single API.
How to use
let { getOauth, getMenus, resolveUrl, PageContent} = require('ezcontent_jsonapi')
let userParams = {
baseURL: "http://example.com", #CMS/API baseURL
request: {
'pathAlias': "/article/article-title",
"queryParams": {
"xyz": "xyz",
}
},
oauth: {
username: "username",
password: "password",
clientSecret: "secret",
clientId: "id"
},
includedFields: [
{
type: "article",
jsonQuery: "include=author,tags&field[node--article]=title"
}
]
}
let output = {};
let pathResolve = null
const oauthToken = await getOauth(userParams);
// resolve URL
let resolve = resolveUrl(userParams, oauthToken);
await resolve.then((resolved) => {
pathResolve = resolved
output['routerResolve'] = resolved
})
.catch(error => {
throw error
})
// get menu
if (pathResolve) {
let menus = getMenus(userParams, "jsonapi", oauthToken);
await menus.then((menusjson) => {
output['menus'] = menusjson
})
.catch(error => {
throw error
})
// get content
let content = new PageContent(pathResolve, userParams, oauthToken).getPageContent();
await content.then((contentjson) => {
for (let key in contentjson) {
output[key] = contentjson[key]
}
})
.catch(error => {
throw error
});
}
return output;
following inputs are optional:
- request.query
- oauth
- includedFields