Implementing the admin endpoint extension
From this article you will learn how to create the admin endpoint extension. Custom admin endpoint extension is used as an example in this article.
Please use the following reference articles to find more details on extensions infrastructure:
Start with a new project
Create a new add-on project named "Sana.Extensions.CustomAdminEndpointExtension" as described in the add-on development tutorial.
Implement the extension class
Create a new class CustomAdminEndpointExtension
inherited from AdminEndpointExtension
.
More information about AdminEndpointExtension
can be found in
AdminEndpointExtension reference article.
public class CustomAdminEndpointExtension : AdminEndpointExtension
{
}
Implement InvokeAsync
method
This method handles an HTTP requests that come from addon specific URL.
See InvokeAsync method of the admin endpoint extension for more details.
The example below can handle the HTTP request with the following URL:
/admin/api/addon/CustomAdminEndpoint/test
public override Task InvokeAsync(AdminEndpointContext context, Func<Task> next, CancellationToken cancellationToken)
{
if (context.Request.Path.StartsWith("test"))
{
return context.Response.WriteAsync("ok", cancellationToken);
}
return next();
}
Implement epic.js
The example below demonstrates how to request data from admin endpoint:
import { ofType } from 'redux-observable';
import {
switchMap,
tap,
} from 'rxjs/operators';
const TEST_REQUESTED = 'TEST_REQUESTED';
const addonId = 'CustomAdminEndpoint';
const epic = (action$, _state$, { api }) => {
const testAddon$ = action$.pipe(
ofType(TEST_REQUESTED),
switchMap(() =>
api.fetch(`/admin/api/addon/${addonId}/test`, {
method: 'POST',
}).pipe(
tap(data => console.log(data))
)),
);
return testAddon$;
};