Try our conversational search powered by Generative AI!

Harinarayanan
Apr 28, 2023
  1238
(3 votes)

Content Delivery / Headless API Implementation

Hi,

I was new to the Headless (CD) implementation and learned with the help of existing resources and implemented it successfully for our requirement, so thought of sharing the implementation steps, in case anyone looking for step by step Content Delivery API implementation or Headless Implementation.

 Below are the tools/platforms I 've used for the implementation,

  1. CMS 11 
  2. React 
  3. ContentDeliveryApi.Cms 2.21.1

Step: 1

Install the below packages through the NuGet package manager.

<package id="EPiServer.ContentDeliveryApi" version="2.19.0" targetFramework="net48" />
  <package id="EPiServer.ContentDeliveryApi.Cms" version="2.21.1" targetFramework="net48" />
  <package id="EPiServer.ContentDeliveryApi.Core" version="2.21.1" targetFramework="net48" />
  <package id="EPiServer.ContentDeliveryApi.Forms" version="2.21.1" targetFramework="net48" />

Step: 2

Add the below configs into web.config, I'm not sure 100% knowledge on why this is required but either of those configs should be set to true, and the other one should be set to false, and not both of them set to true or false.

 <add key="episerver:contentdeliverysearch:maphttpattributeroutes" value="true" />
    <add key="episerver:contentdelivery:maphttpattributeroutes" value="false" />

Step: 3

Add a new Initialization module,

using EPiServer.ContentApi.Cms;
using EPiServer.ContentApi.Core.Configuration;
using EPiServer.Framework;
using EPiServer.Framework.Initialization;
using EPiServer.ServiceLocation;
using System;
using System.Linq;

namespace Alloy.Web.Admin.ContentDeliveryApi
{
    [InitializableModule]
    [ModuleDependency(typeof(ContentApiCmsInitialization))]
    public class ContentDeliveryApiInit : IConfigurableModule
    {
        public void ConfigureContainer(ServiceConfigurationContext context)
        {
            context.Services.Configure<ContentApiConfiguration>(config => {
                config.Default().SetMinimumRoles(String.Empty);
            });
        }

        public void Initialize(InitializationEngine context)
        {
            //Add initialization logic, this method is called once after CMS has been initialized
        }

        public void Uninitialize(InitializationEngine context)
        {
            //Add uninitialization logic
        }
    }
}

Once you are done with the above steps you can re-build and run your solution to verify everything okay with the solution.

If you see your solution is working fine, then you can test Content Delivery API by accessing a site content with the help of Visual Studio Code(I feel it's a very feasible tool to access Headless content), In case if you don't have a REST Client in your Visual Studio Code please install the below Extension, It's really useful during our Headless implementation to test content.

Examples:

To get site definitions:

https://localhost:44300/api/episerver/v2.0/site/

To get your page content:

https://localhost:44300/api/episerver/v2.0/content/420003

To Expand the Content Area/Content reference within Content: 

To Get Language-Specific Content: 
In this way, your content is ready to access through Content Delivery API.
Step 4:
If you above all are working as expected we can move on to the next step.
The next will be creating the Content type, ViewModel, Controller, Basic view, and React development for fetching data and rendering data.
In my case had to create all of the above from scratch, maybe your case may differ. So I like to cover those parts in another blog. 
Please feel free to add your comments, questions, thoughts, or any missing steps.
Thanks for reading. Have a good day. 
Apr 28, 2023

Comments

Manoj Kumawat
Manoj Kumawat May 2, 2023 02:23 PM

Nice! Would be a good idea to write on Search & Navigation usages with ContentSearch.Api next ?

Please login to comment.
Latest blogs
Solving the mystery of high memory usage

Sometimes, my work is easy, the problem could be resolved with one look (when I’m lucky enough to look at where it needs to be looked, just like th...

Quan Mai | Apr 22, 2024 | Syndicated blog

Search & Navigation reporting improvements

From version 16.1.0 there are some updates on the statistics pages: Add pagination to search phrase list Allows choosing a custom date range to get...

Phong | Apr 22, 2024

Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog

Azure AI Language – Abstractive Summarisation in Optimizely CMS

In this article, I show how the abstraction summarisation feature provided by the Azure AI Language platform, can be used within Optimizely CMS to...

Anil Patel | Apr 18, 2024 | Syndicated blog

Fix your Search & Navigation (Find) indexing job, please

Once upon a time, a colleague asked me to look into a customer database with weird spikes in database log usage. (You might start to wonder why I a...

Quan Mai | Apr 17, 2024 | Syndicated blog