close

Filter

loading table of contents...

Headless Server Developer Manual / Version 2301

Table Of Contents

10. REST Access to GraphQL

Although CoreMedia recommends using the GraphQL endpoint to develop modern client applications, it may be desirable to run a client application using a REST API, for different reasons:

  • A REST based client application already exists and can or should not be changed.
  • Reduce network traffic.
  • Limit the type and amount of queries.

While the latter two objectives could be addressed by persisted queries, query whitelisting and other security means (see Section 3.5, “Security”), the first objective is the most common one why you would want to add a REST layer on top of GraphQL.

The rest controller is enabled by default. If REST access is not desired, the controller can be disabled by setting the configuration property caas.graphql-restmapping-controller.enabled = false.

A new REST mapping layer for the Headless Server now allows for issuing REST requests instead of GraphQL queries. A list of REST endpoints can now be configured which map the request to a corresponding Chapter 9, Persisted Queries. Moreover, the query result can optionally be transformed using JSLT in order to meet the client requirements.

All REST endpoints and their corresponding persisted queries are listed and visualized in the Swagger-UI.

CoreMedia delivers the following examples of persisted queries with the Headless Server:

article , page , picture , site

Executes a '... by Id' GraphQL query.

search

Executes a generic 'Search' GraphQL query.

The response of persisted queries using the GraphQL endpoint is JSON as specified by graphql.org. However, it is possible to invoke a JSLT transformation on the result transparently when using the REST endpoint to a persisted query. The files specifying the JSLT transformation must have the same name as the persisted query ID for which they are intended for. These files are stored in the folder resources/transformations. In addition to that, it is possible to define a default or fallback transformation by creating a file called default.jslt (see next Section 10.2, “JSLT Transformation” for details).

The corresponding REST endpoints to the example persisted queries are:

  • https://<your-host>/caas/v1/article/<id>
  • https://<your-host>/caas/v1/page/<id>
  • https://<your-host>/caas/v1/picture/<id>
  • https://<your-host>/caas/v1/site/<siteId>
  • https://<your-host>/caas/v1/search/

Headless server request/response flow using REST

Figure 10.1. Headless server request/response flow using REST


Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.