Embracing the Headless Channel in Xperience by Kentico
Tags: kentico, headless, dxp, webdev
Published: 2024-01-08 14:20:07

In December last year, Xperience by Kentico rolled out :gift: a [significant refresh](https://community.kentico.com/blog/xperience-by-kentico-refresh-december-14-2023), introducing the Headless Channel functionality. This innovative feature is designed to enhance content delivery and management in the digital ecosystem. By leveraging the Headless Channel, users can now seamlessly distribute content across various platforms, including campaign websites, mobile apps, and microsites. This development marks a significant shift in how content is managed and delivered, offering greater flexibility and efficiency :muscle:. In this article, we'll dive into the Headless Channel and discover how it enhances digital content strategies.

## Channel Management in Xperience by Kentico
In Xperience by Kentico, channels are a pivotal concept for organizing and delivering content. These channels include [website channels](https://docs.xperience.io/xp/developers-and-admins/configuration/website-channel-management) for traditional web content, [email channels](https://docs.xperience.io/xp/developers-and-admins/digital-marketing-setup/email-channel-management) for digital marketing, and the brand new [headless channels](https://docs.xperience.io/xp/developers-and-admins/configuration/headless-channel-management) for API-driven content delivery. 

Each channel type serves a specific purpose: website channels focus on content for web presentations, email channels are dedicated to managing and delivering marketing communications :mega:, and headless channels provide greater flexibility for content distribution across various platforms. This segmentation not only refines content management and delivery strategies but also facilitates seamless integrations :gear:, enhancing the effectiveness of digital content across various platforms.

## Advantages of the Headless Channel
The Headless Channel in Xperience by Kentico is designed to simplify content management and distribution. This functionality, which requires minimal development effort to implement, can be [easily activated and configured](https://docs.xperience.io/xp/developers-and-admins/configuration/headless-channel-management#Headlesschannelmanagement-Createheadlesschannels). It enables the efficient distribution of specific content across various applications, services, and online platforms.

This approach is particularly beneficial for teams looking to enhance their digital presence without the need for extensive coding or software development. By leveraging the [GraphQL](https://graphql.org/) API endpoint, developers can prepare and execute queries to retrieve the desired content. This makes the Headless Channel a valuable tool :hammer: for content managers and developers, offering ease of use and practicality.

## The differences between REST and Headless
If you're familiar with the REST service in Kentico Xperience, the Headless functionality is a notable enhancement, offering performance benefits and greater flexibility. While the REST service facilitates the management of system objects or pages, the Headless approach, using a GraphQL API endpoint, streamlines content distribution across multiple channels. Furthermore, it provides content editors with full control :100: over the content they wish to distribute via the headless channel. This not only improves performance but also simplifies the process of repurposing existing content for different platforms.

## Secured by default
In Xperience by Kentico, the security of the Headless channel is organized through [token authentication](https://docs.xperience.io/xp/developers-and-admins/configuration/headless-channel-management#Headlesschannelmanagement-ManageAPIkeys). This model enhances data protection by securing the GraphQL API endpoint, requiring valid API keys :key: for access and permitting only authenticated requests with authorized security tokens.

Furthermore, Xperience by Kentico's headless API enables Cross-Origin Resource Sharing ([CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS )), allowing for effortless integration with web applications across different domains. Configuring the [CorsAllowedOrigins](https://docs.xperience.io/xp/developers-and-admins/development/content-retrieval/retrieve-headless-content#Retrieveheadlesscontent-Cross-originresourcesharing) setting allows you to specify which domains are authorized to access the API, ensuring that responses include the necessary Access-Control-Allow-Origin header.

## Configuration of Headless content
To effectively utilize the Headless Channel in Xperience by Kentico, it's essential to configure headless items. These items are key in determining what content types will be available through the GraphQL API. The approach involves identifying and setting up the specific content types required for your headless channel.

![Configure headless item](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i1m67yor3ohztxinds2w.png)

For existing content stored in the Content Hub, these headless items play a pivotal role. They need to configured to link with reusable content from the Content Hub, ensuring that this content, along with all its associated fields, is readily accessible through GraphQL queries.

## Explained through an example scenario
Consider the following example use case for Xperience by Kentico's headless capabilities, which involves the management and distribution of location data as reusable content. In this example, a 'location' :earth_africa: content model contains details such as address and directions, and it is utilized across multiple web pages through various web channels. 

With the headless functionality, this location data can now also be made available to external sources. By creating a headless item with a content item selector, these locations can be easily selected and offered from a central source.

![Reusable content in headless item](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5246gutd0unrehmdo1ip.png)

Through the built-in GraphQL UI, it is possible to easily extract the entered location data from the system. Only a few [configuration adjustments](https://docs.xperience.io/xp/developers-and-admins/configuration/headless-channel-management#Headlesschannelmanagement-ConfiguretheheadlessAPI) are needed, such as enabling the GraphQL API endpoints. Activating GraphQL introspection is not mandatory, but it is quite handy as it makes the GUI tools available for exploring the schema.

> _Enhance your channel's API security by using the **GraphQlEndpointPath** property to specify a custom and less predictable URL endpoint._

Then, we can easily retrieve our location data, including the data from the linked address content item from the content hub.

![GraphQL result](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6i7f1872kythr9p5va0u.png)

## In conclusion
The introduction of headless functionality in Xperience by Kentico is expected to significantly impact future projects. [Headless activity tracking](https://roadmap.kentico.com/c/189-headless-activity-tracking-data-submission-api) is already on the roadmap, and there's hope for expanding its capabilities to include various types of content from different channels. This indicates Kentico's commitment to evolving its headless capabilities to meet complex future needs. And with such advancements, opting for the headless channel will surely become a 'no-brainer' :wink: