Skip to content

Commit

Permalink
KCL-1219 Update readme for items feed
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiaskamenicky authored and Tobias Kamenicky committed Oct 3, 2019
1 parent 16d47a2 commit ba7d014
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@
</ItemGroup>

<ItemGroup>
<None Update="Fixtures\DeliveryClient\allendale_feed.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Fixtures\DeliveryClient\articles_feed_2.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand All @@ -73,12 +70,6 @@
<None Update="Fixtures\DeliveryClient\complete_content_item_system_type_feed.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Fixtures\DeliveryClient\items_feed_2.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Fixtures\DeliveryClient\items_feed_1.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Fixtures\ServiceCollectionsExtensions\deliveryOptions_as_root.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,20 @@ See [Working with Strongly Typed Models](../../wiki/Working-with-strongly-typed-

## Enumerating all items

There are special cases in which you need to enumerate all items in a project (e.g. cache initialization or project export). This scenario is supported in `IDeliveryClient` by using `DeliveryItemsFeed` that can retrieve items in several batches.
There are special use cases in which you need to get and process a larger amount of items in a project (e.g. cache initialization, project export, static website build). This is supported in `IDeliveryClient` by using `DeliveryItemsFeed` that can iterate over items in small batches. This approach has several advantages:
* You are guaranteed to retrieve all items (as opposed to `GetItemsAsync` and paging when the project is being worked on in Kentico Kontent application)
* You can start processing items right away and use less memory, due to a limited size of each batch
* Even larger projects can be retrieved in a timely manner

```csharp
// Get items feed and iteratively fetch all content items in small batches.
// Get items feed and iteratively process all content items in small batches.
DeliveryItemsFeed feed = client.GetItemsFeed();
List<ContentItem> allContentItems = new List<ContentItem>();
while(feed.HasMoreResults)
{
DeliveryItemsFeedResponse response = await feed.FetchNextBatchAsync();
allContentItems.AddRange(response);
foreach(ContentItem item in response) {
ProcessItem(item);
}
}
```

Expand All @@ -137,17 +141,18 @@ There is also a strongly-typed equivalent of the feed in `IDeliveryClient` to su
```csharp
// Get strongly-typed items feed and iteratively fetch all content items in small batches.
DeliveryItemsFeed<Article> feed = client.GetItemsFeed<Article>();
List<Article> allContentItems = new List<Article>();
while(feed.HasMoreResults)
{
DeliveryItemsFeedResponse<Article> response = await feed.FetchNextBatchAsync();
allContentItems.AddRange(response);
foreach(Article article in response) {
ProcessArticle(article);
}
}
```

### Filtering
### Filtering and localization

Filtering is very similar to `GetItems` method, except for `DepthParameter`, `LimitParameter`, and `SkipParameter`. These are not supported in items feed.
Both filtering and language selection are very similar to `GetItems` method, except for `DepthParameter`, `LimitParameter`, and `SkipParameter` parameters. These are not supported in items feed.

```csharp
// Get a filtered feed of the specified elements of
Expand All @@ -160,14 +165,12 @@ DeliveryItemsFeed feed = await client.GetItemsFeed(
);
```

## Limitations
### Limitations

Since this method has very specific usage scenarios the response does not contain linked items, although, components are still included in the response.
Since this method has specific usage scenarios the response does not contain linked items, although, components are still included in the response.

Due to not supported skip and limit parameters, the size of a single batch may vary and it is not recommended to dependend on it in any way. The only guaranteed outcome is that once `HasMoreResults` property is false, you will have retrieved all the filtered items.

**If you need to retrieve all the items and don't care about modular content, feel free to use the items feed. Otherwise, stick with the `GetItems` overloads.**

## Previewing unpublished content

To retrieve unpublished content, you need to create an instance of the `IDeliveryClient` with both Project ID and Preview API key. Each Kentico Kontent project has its own Preview API key.
Expand Down

0 comments on commit ba7d014

Please sign in to comment.