Skip to content

kkostov/ex_wagtail_content_client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ExWagtailContentClient Hex.pm Version Hex Docs CI

Elixir library for consuming the Wagtail content API

Installation

If available in Hex, the package can be installed by adding ex_wagtail_content_client to your list of dependencies in mix.exs:

def deps do
  [
    {:ex_wagtail_content_client, "~> 0.3.0"},
  ]
end

Usage

The library is a simple REST API client fo the default Wagtail Content API. It's intended for accessing content based on the /v2/pages, /v2/images and /v2/documents endpoints.

There are two key methods to consider.

Listing collections

Use the list method to list the contents of a collection:

{:ok, items, meta, info} = ExWagtailContentClient.list :pages, base_url: "https://iamkonstantin.eu"

The returned items are:

  • items - a list of the JSON objects returned by the Wagtail API (the nested items field from the raw response).

  • meta - the JSON meta object returned bu the Wagtail API.

  • info - a map created by the library to include pagination information like the total number of items and helpers for the next and previous query.

Get detail of a resource

Individual items can be retrieved by their detail_url:

{:ok, content} = ExWagtailContentClient.detail "https://iamkonstantin.eu/api/v2/pages/45/"

By default, the content of all paragraph blocks in the body field of the resource (if available) will be sanitized and stripped of all but basic html tags so that it's suitable for rendering in a webpage. You can configure which fields and blocks are sanitized.

License

Copyright 2024 Konstantin [email protected]

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

Elixir library for consuming the Wagtail content API

Topics

Resources

License

Stars

Watchers

Forks

Languages