项目作者: adobe

项目描述 :
AEM Headless Client for Node.js
高级语言: JavaScript
项目地址: git://github.com/adobe/aem-headless-client-nodejs.git
创建时间: 2021-05-28T16:24:08Z
项目社区:https://github.com/adobe/aem-headless-client-nodejs

开源协议:Other

下载


@adobe/aem-headless-client-nodejs"">Version
@adobe/aem-headless-client-nodejs"">Downloads/week
Build Status
License

AEM Headless Client for NodeJS

See aem-headless-client-java for the Java variant of this client
and aem-headless-client-js for the client-side Browser only variant.

Installation

  1. $ npm install @adobe/aem-headless-client-nodejs

Usage

Create AEMHeadless client

  1. const { AEMHeadless } = require('@adobe/aem-headless-client-nodejs');

Configure SDK with serviceURL and Auth data (if needed)

  1. const aemHeadlessClient = new AEMHeadless({
  2. serviceURL: '<aem_host>',
  3. endpoint: '<graphql_endpoint>',
  4. auth: '<aem_token>' || ['<aem_user>', '<aem_pass>']
  5. })
  6. // Eg:
  7. const aemHeadlessClient = new AEMHeadless({
  8. serviceURL: AEM_HOST_URI,
  9. endpoint: 'content/graphql/endpoint.gql',
  10. auth: [AEM_USER, AEM_PASS]
  11. })

Use AEMHeadless client

Promise syntax:

  1. aemHeadlessClient.runQuery(queryString)
  2. .then(data => console.log(data))
  3. .catch(e => console.error(e.toJSON()))
  4. aemHeadlessClient.listPersistedQueries()
  5. .then(data => console.log(data))
  6. .catch(e => console.error(e.toJSON()))
  7. aemHeadlessClient.persistQuery(queryString, 'wknd/persist-query-name')
  8. .then(data => console.log(data))
  9. .catch(e => console.error(e.toJSON()))
  10. aemHeadlessClient.runPersistedQuery('wknd/persist-query-name')
  11. .then(data => console.log(data))
  12. .catch(e => console.error(e.toJSON()))

Within async/await:

  1. (async () => {
  2. let postData
  3. try {
  4. postData = await aemHeadlessClient.runQuery(queryString)
  5. } catch (e) {
  6. console.error(e.toJSON())
  7. }
  8. let list
  9. try {
  10. list = await aemHeadlessClient.listPersistedQueries()
  11. } catch (e) {
  12. console.error(e.toJSON())
  13. }
  14. try {
  15. await aemHeadlessClient.persistQuery(queryString, 'wknd/persist-query-name')
  16. } catch (e) {
  17. console.error(e.toJSON())
  18. }
  19. let getData
  20. try {
  21. getData = await aemHeadlessClient.runPersistedQuery('wknd/persist-query-name')
  22. } catch (e) {
  23. console.error(e.toJSON())
  24. }
  25. })()

Fetch instance

Check https://github.com/adobe/aio-lib-core-networking for advanced usage and default settings

Authorization

If auth param is a string, it’s treated as a Bearer token

If auth param is an array, expected data is [‘user’, ‘pass’] pair, and Basic Authorization will be ued

If auth is not defined, Authorization header will not be set

DEV token and service credentials

SDK contains helper function to get Auth token from credentials config file

  1. const { getToken } = require('@adobe/aem-headless-client-nodejs')
  2. (async () => {
  3. const { accessToken, type, expires } = await getToken('path/to/service-config.json')
  4. const aemHeadlessClient = new AEMHeadless('content/graphql/endpoint.gql', AEM_HOST_URI, accessToken)
  5. const data = await aemHeadlessClient.runQuery(queryString)
  6. })()

API Reference

See generated API Reference

Contributing

Contributions are welcome! Read the Contributing Guide for more information.

Licensing

This project is licensed under the Apache V2 License. See LICENSE for more information.