Excontentstack.Delivery.Entries (Excontentstack v0.5.1)

Read-only operations on entries via the Delivery API.

Summary

Functions

Retrieves a single entry by content type and entry UID.

Lists entries for a given content type.

Lists all entries for a given content type, handling pagination automatically.

Streams all entries for a given content type with lazy, memory-efficient pagination.

Functions

get(client, content_type_uid, entry_uid, opts \\ [])

Retrieves a single entry by content type and entry UID.

list(client, content_type_uid, opts \\ [])

Lists entries for a given content type.

Returns a single page of entries. Use list_all/3 to automatically fetch all entries across multiple pages.

Options:

  • :params – query params like :limit, :skip, :include, etc.
  • :raw – if true, returns full response metadata

Returns {:ok, %{entries: [...]}} or {:error, reason}.

list_all(client, content_type_uid, opts \\ [])

Lists all entries for a given content type, handling pagination automatically.

Fetches all pages and returns the complete dataset. For large content types, consider using list/3 with manual pagination instead.

Options:

  • :params – query params like :include, :locale, etc. Note: If :limit is provided and less than 100, only one request is made.

Returns {:ok, entries} or {:error, reason}.

Examples

# Fetch all entries
{:ok, all_entries} = Entries.list_all(client, "blog_post")

stream(client, content_type_uid, opts \\ [])

Streams all entries for a given content type with lazy, memory-efficient pagination.

Returns a Stream that fetches entries on-demand page-by-page (100 entries per page). This is ideal for processing large content types without loading everything into memory.

Unlike list_all/3 which loads all entries upfront, stream/3 only fetches pages as they are consumed, enabling early termination and memory-efficient pipelines.

Options

  • :params – query params like :include, :locale, etc. Note: :limit and :skip are managed internally for pagination and will be overridden.

Returns

Returns an Enumerable.t() (Stream) that yields individual entries.

Errors during stream consumption will raise a RuntimeError. Validate inputs before consuming the stream to catch configuration errors early.

Examples

# Batch processing with chunking
client
|> Entries.stream("blog_post", params: [locale: "en-us"])
|> Stream.chunk_every(50)
|> Enum.each(fn batch -> process_batch(batch) end)

# Early termination - only fetches first page
client
|> Entries.stream("blog_post")
|> Enum.take(10)

# Filter and transform pipeline
client
|> Entries.stream("blog_post")
|> Stream.filter(fn entry -> entry["published"] == true end)
|> Stream.map(fn entry -> entry["title"] end)
|> Enum.to_list()

# Process and discard
stream(client, "blog")
|> Stream.each(&send_to_analytics/1)
|> Stream.run() # Nothing kept in memory

# Filter before materializing
stream(client, "blog")
|> Stream.filter(&published?/1)
|> Enum.to_list()

# Avoid this - it defeats the purpose of streaming
client
|> Entries.stream("blog_post")
|> Enum.to_list()