So, using this, you could make a request to the Delivery API to get the details for the page, extract the ID for the picked form, and initiate a second request to the Forms API to retrieve the full details of the form. With both together, you could render the page.
Wouldn’t it be nice though to be able to do this in one request? Well, you can… by implementing the interface mentioned earlier. Instead of returning the raw value, we could retrieve the full details of the form and a serialized representation of that.
However, it could be that you don’t want the full details for the request you are making, so it might not be a good idea to bake this behaviour in for every request. In the case of Forms, it would mean an additional database request and some further server-side work that would be necessary before the Delivery API response could be returned.
Fortunately, there’s a nice option with the Delivery API to allow us to defer this decision to the client making the request – and they can take a call as to whether for a particular case they want the full form details, as opposed to others where they either don’t need it or the ID alone is sufficient. This is known as output expansion.
As of Umbraco 12 RC 3, the state of the expansion request for a particular property is propagated to the property editor, via the expanding parameter available in the ConvertIntermediateToDeliveryApiObject method signature. We’ve used this in Forms in the following way.
Firstly, we define a type to represent the form output in the Delivery API. It contains two properties, the picked form's ID and a form representation that is the same as that retrievable from the Forms API:
If we are not “expanding”, we just populate the form’s ID, leading to an output of: