Make your apps robust and responsive by following our recommendations and best practices.
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 to some underlying connection issues. It may also happen that the Delivery API denies 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. Make sure your app responds to any connection issues by retrying the requests after a short while.
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.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 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 query 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.Keep in mind that using this parameter may result in slower responses because the API counts the items per request.
Leverage stale content where possibleMost applications don’t need updated content right after it’s published. Our CDN provides stale content until it is replaced with updated content in the background. You can recognize stale content by checking if the X-Stale-Contentresponse header is set to 1.