Sanity (sanity v0.6.1) 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.
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.
Generates a request for the asset endpoint.
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
.
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
:api_version
- The default value is"v2021-03-25"
.: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.
Specs
Generates a request for the asset endpoint.
Options
:asset_type
- Either:image
or:file
. The default value is:image
.:content_type
- Optionalcontent-type
header. It appears that Sanity is able to infer image types.
Query params
Sanity doesn't document the query params very well at this time, but the Sanity Javascript client lists several possible query params:
label
- Labeltitle
- Titledescription
- Descriptionfilename
- Original filenamemeta
- ???creditLine
- The credit to person(s) and/or organization(s) required by the supplier of the image to be used when published