The Content Delivery API is a module that extends your Redakt application with an endpoint that can be used to request published content. This is useful for headless operation with single-page or mobile applications, that do not need the full rendering engine of a traditional web application. You can use the Content Delivery API both in combination with the Redakt.ContentManagement.Web web rendering package, or you can exclude web rendering altogether and use the Content Delivery API on its own. The Content Delivery API is installed through an optional NuGet package.

The Content Delivery API is a REST Web API based on the OpenAPI v3 specification. The OpenAPI specification file can be used to automatically generate clients for many frontend and backend technologies. All your content models will be included as fully typed OpenAPI schemas in the specification.

Installation

Install the package with the NuGet package manager or the Package Manager Console.

PM> Install-Package Redakt.ContentManagement.Web.Api

Service registration

Register Content Delivery API services in the ConfigureServices() method of your project's Startup.cs file by adding an AddContentApi() call to the Redakt builder instance. The order in which services are added to the Redakt builder is not important.

public void ConfigureServices(IServiceCollection services)
{
    // ... framework and other services here

    var builder = services.AddRedakt(this.Configuration);
    builder.AddContentApi();
    // ... other Redakt services
}

Configuration settings

The Content Delivery API can be configured through the appsettings.json file. Any configuration that is not included in the appsettings.json file will be set to the following default values. Additionally, an Action<RedaktContentApiOptions> configuration delegate may be passed to the AddContentApi() call. Configuration set through this delegate takes priority and overrides values in the appsettings.json file.

{
    "Redakt": {
        "ContentApi": {
            "OpenApi": {
                "RootPath": "/api/",
                "SpecificationPath": "openapi.json"
            }
        }
    }
}

OpenAPI Root Path

This is the absolute URL that the Content Delivery API is served from. You can change this if the API URL would conflict with your own website content, or if you prefer a different root URL.

If you are hosting the Content Delivery API on a separate website and hostname, you could also set this to the website root (/), in which case the API will be available on the hostname root URL (f.e. https://api.mywebsite.com).

OpenAPI Specification Path

This is the file path (relative to the API root path) that the OpenAPI v3 specification JSON file will be served from. The OpenAPI specification file can be used to generate client SDKs and documentation for your API, with tools such as Swagger Codegen / Swagger UI, and OpenAPI generator.

Middleware registration

The Content Delivery API requires its middleware to be inserted into the ASP.NET Core request pipeline of your web project. Add the middleware to the request pipeline in the Configure() method of your project's Startup.cs file. The code snippet below shows the correct order in which to add Redakt middleware when you're also including other Redakt middleware in this project.

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    // ... other pipeline configuration here

    // Other Redakt middleware registration
    app.UseRedaktIdentityServer();
    app.UseRedaktBackOffice();
    app.UseRedaktPageRendering();
    // Content Delivery API
    app.UseRedaktContentApi();
}