This is an Elixir-based SDK for Prismic.io Mostly based on https://github.com/prismicio/ruby-kit and https://github.com/prismicio/javascript-kit
- The primary authors of this library are:
- Coburn Berry (coburncoburn)
- API
- Cache
- Predicates
- David Wu (sudostack)
- Fragments
- Parser
- TODOs:
- Add caching on api entrypoint request ( Prismic.api/2 )
- Add optional caching on document requests ( submitting search form )
- Support authentication in the API
def deps do
[
{:prismic, git: "https://github.com/TheRealReal/prismic-elixir", branch: "master"}
]
end
set repo url in your project's config
config :prismic,
repo_url: "https://micro.cdn.prismic.io/api"
Prismic.V2.API.new()
|> SearchForm.from_api()
|> SearchForm.set_ref(<ref>) # master ref / versioned ref
|> SearchForm.set_query_predicates([Predicate.at("document.id", <id>)])
|> SearchForm.submit()
|> Map.fetch!(:results)
|> Parser.parse_documents() # %Prismic.Document{id: ..., uid: ..., href: ..., fragments...}
The default HTTP Client is Poison. It is possible to use any http client that implements the Prismic.HTTPClient behaviour .
Then, set the HTTPClient Module in config or within
Application.put_env(:prismic, :http_client_module, MyApp.HTTPClient)
The default Cache is an Agent . It is possible to use any cache that implements the Prismic.Cache behaviour .
Then, set the Cache Module in config or within
Application.put_env(:prismic, :cache_module, MyApp.Cache)
Only the first leg of the request ( api entrypoint ) is cached. Actual document queries are not cached. It is probably better to just cache calls to the library itself rather than worrying about caching in the library.