Improve your development experience by using strongly typed models based on your Kontent.ai content types.
Life without strongly typed models
When getting content directly from the Delivery REST API, you receive content items as JSON objects. Your app then needs to parse the JSON to display your content. For example, to access the Headline element in a content item, you'd use a notation like this response.data.item.elements.headline.value.In a more complicated scenario, this approach becomes cumbersome. It forces you to remember the JSON structure of your content items and the codenames of your content elements.To make this easier, use a Delivery SDK to map the retrieved content items to their strongly typed models.
Use strongly typed models
This practice has several advantages:
type safety during compile-time
convenience (IntelliSense remembers content type properties for you)
support of type-dependent functionalities
The models are plain classes with no attached behavior or dependency on an external framework. Each model corresponds to a content type in your Kontent.ai project.To create a content type’s representation in code, you need a class with properties representing the individual content elements:
Each property is mapped to its content element's codename either explicitly or using a naming convention. For example, codename body_text becomes property bodyText.
Properties are usually typed using classes provided by the SDK.
Depending on the SDK, simple content elements (like text and number) are sometimes represented using native types (like string and integer).
The following example is a strongly typed model of the Homepage content type.
Use the model generator to create strongly typed models from your Kontent.ai project by providing your project’s environment ID.