Hi,
I wish to write a simple code that I searched and tested to return the JSON like Delivery API and not overloaded like to return direct Content Type.
Do you have some suggestions?
How to query the data with DeliveryApi SDK?
using Umbraco.Cms.Core.DeliveryApi;
.... inject interface:
private readonly IApiContentQueryService _apiContentQueryService;
private readonly IApiContentRouteBuilder _apiContentRouteBuilder;
private readonly IApiContentBuilder _apiContentBuilder;
public DemoController(
.... IApiContentRouteBuilder apiContentRouteBuilder,
IApiContentBuilder apiContentBuilder
)
{
....
_apiContentQueryService = apiContentQueryService;
_apiContentRouteBuilder = apiContentRouteBuilder;
_apiContentBuilder = apiContentBuilder;
}
public async Task<IActionResult> Content(int id)
{
var content = _contentService.GetById(id);
if (content == null)
return NotFound();
var flag = await IsAuthorizedToSeeData(id, email);
if (flag)
{
var iii = _apiContentRouteBuilder.Build(_publishedContentQuery.Content(id));
var cc = _apiContentBuilder.Build(_publishedContentQuery.Content(id));
return Ok(cc);
}
else
return Unauthorized();
}
This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/113656-deliveryapi-simple-code-to-return-publishcontent-as-delivery-api-content-json-format