Make your apps robust and responsive by following our recommendations and best practices.
Use SDKs
Instead of directly creating requests and queries to APIs, we recommend using an SDK. SDKs are tools that help you easily communicate with services like Delivery REST API. SDKs also help you develop faster.There are several advantages to using an SDK with Delivery API.
Resolve hypertext links and render components within your content items.
Rely on the built-in retry policy to handle common connection issues and rate limitations.
Easily discover more API features.
Additions or changes to the Delivery API are quickly reflected in our official SDKs. All SDKs are open source on GitHub, which means you can submit issues with ideas for improvements.
Make precise requests
If all you need are URL slugs of your articles (for example, to build a navigation hierarchy), filtering out anything you don’t need is good practice. That means requesting only a specific element value in your API requests. With more specific requests like this, the API responds faster, and you get smaller response sizes.For best performance when fetching data from Kontent.ai via Delivery REST API, we recommend you follow these guidelines:
If you need a specific subset of elements instead of the whole content item, specify the elements using the elements filter. This applies to linked items as well.
If you need to get items based on certain criteria (such as an element’s value), use filtering.
If you need to get a hierarchy of items, set the depth parameter to a value you require. Try to keep it low. The higher the depth, the higher the response times.
If you’re building a static site, warming up your app’s cache, or exporting your project, use the enumerate content items endpoint. This endpoint is useful when you require most of your project’s content (for example, to create a mapping between the items) and don’t need linked items.
If you’re displaying assets from your project, optimize images to save bandwidth.
Paginate your requests
To decrease the size of a single request and increase speed, use pagination parameters skip and limit.API responses might contain up to 2000 content items (including linked content). By using pagination from the beginning, you’ll have an easy time even when your project gets bigger, and you move from hundreds to thousands of items.
Retry what fails
Due to the nature of the Internet, any request can fail due to underlying connection issues. The Delivery API may also deny your request because of rate limitations.If that happens, check the Retry-After header’s value, wait the specified number of seconds, and try the request again. Retrying the requests after a short while will ensure that your app responds to any connection issues.
Cache what you get
Caching helps eliminate the wait time that your app users might experience when your app gets content from an API or suffers temporary connection issues. Every app that retrieves content (or data in general) from external resources benefits from caching.Most applications don’t need updated content right after it’s published. When content in the CDN becomes stale, the CDN provides the stale cached content until it is replaced with updated content in the background.Depending on how quickly you want to display published changes in your app (because not all changes are time-critical), you need to choose a caching approach.
Store video with a 3rd party
You can use Delivery API to download video files from your project but not for streaming video.If you need to store video files and let your users stream them in your app, we recommend using specialized third-party services like YouTube, Vimeo, and similar.
Consider securing your content
New Kontent.ai projects are publicly available by default. Anyone can access your project’s published content (if they know your project’s environment ID) and peek inside.If you need your content to stay private (for example, when internal documents or customer data are part of your content), we recommend enabling secure access for Delivery API.With Advanced Asset Management, you can also restrict access to your assets, which are otherwise public by default.
Sign in with your Kontent.ai credentials or sign up for free to unlock the full lesson, track your progress, and access exclusive expert insights and tips!
Consider GraphQL queriesWith Kontent.ai’s native Delivery GraphQL API, you can query for any number of items with just one request. You write a query for the exact data you need using the GraphQL API, and the API fetches the resources for you.
Need paged navigation in your app?If you want to create a paged navigation that displays the total number of items, use the includeTotalCount parameter in your request. With this parameter, you’ll get the total number of content items matching your query. The items omitted by parameters like limit are included in the count.Remember that using this parameter may result in slower responses because the API needs to count the items per request.