View Source Contentful.Delivery.Entries (Contentful SDK v0.6.0)
Entries allows for querying the entries of a space via Contentful.Query
.
fetching-a-single-entry
Fetching a single entry
import Contentful.Query
alias Contentful.Delivery.Entries
{:ok, entry} = Entries |> fetch_one("my_entry_id")
simple-querying-of-a-collection-of-entries
Simple querying of a collection of entries
import Contentful.Query
alias Contentful.Delivery.Entries
# fetches the entries based on the `space_id`, `environment` and `access_token` in config/config.exs
{:ok, entries, total: _total_count_of_entries} =
Entries |> fetch_all
# fetches the entries by passing `space_id`, `environment` and `access_token`
space_id = "<my_space_id>"
environment = "<my_environment>"
access_token = "<my_access_token>"
{:ok, entries, total: _total_count_of_entries} =
Entries |> fetch_all(space_id, environment, access_token)
more-advanced-query-with-included-links
More advanced query with included links
Entries can have links included, which limits the amount of times a client has to request data from the server:
import Contentful.Query
alias Contentful.{Asset, Entry}
alias Contentful.Delivery.Entries
# The default include depth is 1 (max 10)
{:ok, [ %Entry{} = entry | _ ], total: _total_count_of_entries} =
Entries |> include |> fetch_all
# any links within entry.fields will have been replaced with actual entities (e.g. an %Asset{] or %Entry{} struct)
accessing-common-resource-attributes
Accessing common resource attributes
Entries embed Contentful.SysData
with extra information about the entry:
import Contentful.Query alias Contentful.{ContentType, Entry, SysData} alias Contentful.Delivery.Entries
= Entries |> fetch_one("my_entry_id")
"my_entry_id" = entry.id "<a timestamp for updated_at>" = entry.sys.updated_at "<a timestamp for created_at>" = entry.sys.created_at "<a locale string>" = entry.sys.locale %ContentType{id: "the_associated_content_type_id"} = entry.sys.content_type
Link to this section Summary
Functions
maps a standard API response for queries compliant with the Contentful.Queryable
behaviour.
maps a standard API response for a single entry returned, compliant with the Contentful.Queryable
behaviour.
Link to this section Functions
maps a standard API response for queries compliant with the Contentful.Queryable
behaviour.
maps a standard API response for a single entry returned, compliant with the Contentful.Queryable
behaviour.