Piggybacking on Content Delivery API to Grab Content as JSON (from C#)

This is almost certainly a misuse of the code behind the Content Delivery API in Umbraco, but I’ve discovered IApiContentResponseBuilder as a nice way to convert data from Umbraco into JSON.

Given a content node, I make a call to Build(iPublishedContentHere) and get the same JSON representation I would if I had made an API call.

What I am having trouble doing is passing faux arguments to control:

  • Property Expansion (expand)
  • Property Limiting (fields)

I may be crazy, but has anyone found themselves doing the same? I use this all the time to grab JSON representation of content or specific blocks and pass them to my web components on the frontend. I’ve also found it beneficial to use in my SignalR hubs.

If I could find a way to implement the expand and fields params, I’d be set.

Here’s what I did:

  1. Write an IOutputExpansionStrategy. You can begin with Umbraco’s from source control as a starting point. I decided to, for simplicity, to expand everything by default.
  2. Write an IOutputExpansionStrategyAccessor whose only purpose is to initiate our Output Expansion Strategy class from Step 1.
  3. I registered the class from Step 2 as a singleton-service in a IComposer.

For now I have what I need to create an ApiContentBuilder, reference my new Strategy, and expand / limit as desired.

Hi @markadrake

Have you got any example code of what you did to achieve this, as I currently have a similar strategy to you using the IApiContentResponseBuilder and would be nice to be able to expand from C# with additional properties.