|
1 | 1 | --- |
2 | 2 | description: >- |
3 | | - Discover how to customize the Content Delivery API's response for your custom |
4 | | - property editors. |
| 3 | + Discover how to customize the Content Delivery API's response for custom property editors. |
5 | 4 | --- |
6 | 5 |
|
7 | 6 | # Custom property editors support |
8 | 7 |
|
9 | | -Out of the box, the Delivery API supports custom property editors, ensuring they are rendered alongside the built-in ones in Umbraco. However, if the output generated by your property editor isn't optimal for a headless context, you have the ability to customize the API response. This customization won't impact the Razor rendering, allowing you to tailor the Content Delivery API response according to your specific requirements. |
| 8 | +Out of the box, the Delivery API supports custom property editors, ensuring they are rendered alongside the built-in ones in Umbraco. However, if the output generated by a property editor isn't optimal for a headless context, developers can customize the API response. This customization won't impact the Razor rendering, allowing developers to tailor the Content Delivery API response according to their specific requirements. |
10 | 9 |
|
11 | | -In this article, we'll look into how you can work with the `IDeliveryApiPropertyValueConverter` interface and implement custom [property expansion](./property-expansion-and-limiting.md) for your custom property editors. |
| 10 | +This article will demonstrate how to work with the `IDeliveryApiPropertyValueConverter` interface and implement custom [property expansion](./property-expansion-and-limiting.md) for custom property editors. |
12 | 11 |
|
13 | 12 | ## Prerequisite |
14 | 13 |
|
15 | 14 | The examples in this article revolve around the fictional `My.Custom.Picker` property editor. This property editor stores the key of a single content item and is backed by a property value converter. |
16 | 15 |
|
17 | | -We will not dive into the details of creating a custom property editor for Umbraco in this article. If you need guidance on that, please refer to the [Creating a Property Editor](../../tutorials/creating-a-property-editor/README.md) and [Property Value Converters](../../customizing/property-editors/property-value-converters.md) articles. |
| 16 | +This article will not dive into the details of creating a custom property editor for Umbraco. Guidance on that can be found in these articles: [Creating a Property Editor](../../tutorials/creating-a-property-editor/README.md) and [Property Value Converters](../../customizing/property-editors/property-value-converters.md). |
18 | 17 |
|
19 | 18 | ## Implementation |
20 | 19 |
|
21 | | -To customize the output of a property value editor in the Delivery API, we need to opt-in by implementing the `IDeliveryApiPropertyValueConverter` interface. |
| 20 | +To customize the output of a property value editor in the Delivery API, opt-in by implementing the `IDeliveryApiPropertyValueConverter` interface. |
22 | 21 |
|
23 | | -The code example below showcases the implementation of this interface in the property value converter for `My.Custom.Picker`. Our focus will be on the methods provided by the `IDeliveryApiPropertyValueConverter`, as they are responsible for customizing the Delivery API response. |
| 22 | +The code example below showcases the implementation of this interface in the property value converter for `My.Custom.Picker`. The focus will be on customizing the methods provided by the `IDeliveryApiPropertyValueConverter`, as they are responsible for customizing the Delivery API response. |
24 | 23 |
|
25 | | -Towards the end of the example, you will find the response models that we will be using. |
| 24 | +Response model classes can be found near the end of this article. |
26 | 25 |
|
27 | 26 | The `IsConverter()` and `GetPropertyValueType()` methods are inherited from the `PropertyValueConverterBase` class, which is covered in the [Property Value Converters](../../customizing/property-editors/property-value-converters.md) article. |
28 | 27 |
|
29 | 28 | {% include "../../.gitbook/includes/obsolete-warning-snapshot.md" %} |
30 | 29 |
|
31 | 30 | {% code title="MyCustomPickerValueConverter.cs" lineNumbers="true" %} |
32 | | - |
33 | 31 | ```csharp |
34 | 32 | using Umbraco.Cms.Core.DeliveryApi; |
35 | 33 | using Umbraco.Cms.Core.Models.DeliveryApi; |
@@ -115,7 +113,6 @@ public class DeliveryApiItemDetails |
115 | 113 | public IApiContentRoute? Route { get; set; } |
116 | 114 | } |
117 | 115 | ``` |
118 | | - |
119 | 116 | {% endcode %} |
120 | 117 |
|
121 | 118 | The Implementation of the `IDeliveryApiPropertyValueConverter` interface can be found in the following methods: |
@@ -163,9 +160,9 @@ GET /umbraco/delivery/api/v2/content/item/blog |
163 | 160 |
|
164 | 161 | ## Property expansion support |
165 | 162 |
|
166 | | -Property expansion allows us to conditionally add another level of detail to the Delivery API output. Usually, these additional details are "expensive" to retrieve (for example, requiring database access to populate). By applying property expansion, we provide the option for the caller of the API to opt-in explicitly to this "expensive" operation. From the caller's perspective, the alternative might be an even more expensive additional round-trip to the server. |
| 163 | +Property expansion allows developers to conditionally add another level of detail to the Delivery API output. Usually, these additional details are "expensive" to retrieve (for example, requiring database access to populate). By applying property expansion, Umbraco developers provide the option for the caller of the API to opt-in explicitly to this "expensive" operation. From the caller's perspective, the alternative might be an even more expensive additional round-trip to the server. |
167 | 164 |
|
168 | | -In our example, property expansion is implemented within `ConvertIntermediateToDeliveryApiObject()`. By considering the value of the `expanding` parameter, we can modify the `BuildDeliveryApiCustomPicker()` method as follows: |
| 165 | +In this example, property expansion is implemented within `ConvertIntermediateToDeliveryApiObject()`. By considering the value of the `expanding` parameter, the `BuildDeliveryApiCustomPicker()` method can be modified as follows: |
169 | 166 |
|
170 | 167 | {% include "../../.gitbook/includes/obsolete-warning-ipublishedsnapshotaccessor.md" %} |
171 | 168 |
|
@@ -202,9 +199,9 @@ private DeliveryApiCustomPicker? BuildDeliveryApiCustomPicker(object inter, bool |
202 | 199 | } |
203 | 200 | ``` |
204 | 201 |
|
205 | | -If the `expanding` parameter is `false`, the method returns the same shallow representation of the referenced content item as before. Otherwise, we retrieve the corresponding `IPublishedContent` and construct our response object accordingly. |
| 202 | +If the `expanding` parameter is `false`, the method returns the same shallow representation of the referenced content item as before. Otherwise, retrieve the corresponding `IPublishedContent` and construct the response object accordingly. |
206 | 203 |
|
207 | | -To see the expanded output in the API response, we need to add the `expand` query parameter to our request. We can use either `?expand=properties[$all]` to expand all properties or `?expand=properties[pickedItem]` to expand the specific `'pickedItem'` property. |
| 204 | +To see the expanded output in the API response, add the `expand` query parameter to the request. This parameter can be applied using either `?expand=properties[$all]` to expand all properties or `?expand=properties[pickedItem]` to expand the specific `'pickedItem'` property. |
208 | 205 |
|
209 | 206 | **Request** |
210 | 207 |
|
|
0 commit comments