Best practices for getting content in your app
0% complete
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.
- Use strongly typed models so that you easily work with typed content.
- Rely on the built-in retry policy to handle common connection issues and rate limitations.
- Easily discover more API features.
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.- If you need a single content item, use the retrieve a content item endpoint.
- 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 parametersskip
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 theRetry-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
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!