Sanity (sanity v0.3.0) View Source
Client library for Sanity CMS. See the README for examples.
Link to this section Summary
Functions
Generates a request for the Doc endpoint.
Convenience function for fetching a single document by ID. See doc/1
.
Convenience function for fetching a list of documents by ID. See doc/1
.
Generates a request for the Mutate endpoint.
Generates a request to the Query endpoint. Requests to this endpoint may be authenticated or unauthenticated. Unauthenticated requests to a dataset with private visibility will succeed but will not return any documents.
Submits a request to the Sanity API. Returns {:ok, response}
upon success or {:error, response}
if a non-exceptional (4xx) error occurs. A Sanity.Error
will be raised if an
exceptional error, such as a 5xx response code or a network timeout, occurs.
Like request/2
, but raises a Sanity.Error
instead of returning and error tuple.
Link to this section Functions
Specs
doc(String.t()) :: Sanity.Request.t()
Generates a request for the Doc endpoint.
The Sanity docs suggest using this endpoint sparingly because it is "less scalable/performant"
than using query/3
. See get_document/2
and get_documents/2
for a more convenient
interface.
Specs
Convenience function for fetching a single document by ID. See doc/1
.
See request/2
for supported options.
Specs
Convenience function for fetching a list of documents by ID. See doc/1
.
The order/position of documents is preserved based on the original list of IDs. If any documents
cannot be found then the returned list will contain nil
for that document.
See request/2
for supported options.
Specs
mutate([map()], keyword() | map()) :: Sanity.Request.t()
Generates a request for the Mutate endpoint.
Example
Sanity.mutate(
[
%{
create: %{
_type: "product",
title: "Test product"
}
}
],
return_ids: true
)
|> Sanity.request(config)
Specs
Generates a request to the Query endpoint. Requests to this endpoint may be authenticated or unauthenticated. Unauthenticated requests to a dataset with private visibility will succeed but will not return any documents.
Specs
request(Sanity.Request.t(), keyword()) :: {:ok, Sanity.Response.t()} | {:error, Sanity.Response.t()}
Submits a request to the Sanity API. Returns {:ok, response}
upon success or {:error, response}
if a non-exceptional (4xx) error occurs. A Sanity.Error
will be raised if an
exceptional error, such as a 5xx response code or a network timeout, occurs.
Options
:cdn
- Should the CDN be used? See the Sanity docs for details. The default value isfalse
.:dataset
- Sanity dataset.:http_options
- Options to be passed toFinch.request/3
. The default value is[]
.:project_id
- Sanity project ID.:token
- Sanity auth token.
Specs
request!(Sanity.Request.t(), keyword()) :: Sanity.Response.t()
Like request/2
, but raises a Sanity.Error
instead of returning and error tuple.
See request/2
for supported options.