JSON.LD.DocumentLoader.RemoteDocument (JSON-LD.ex v1.0.0)

View Source

Implementation of the JSON-LD 1.1 Remote Document and Context Retrieval specification.

This module provides both:

  1. A struct representing remote documents as specified in https://www.w3.org/TR/json-ld11-api/#remotedocument
  2. The core implementation of remote document loading according to https://www.w3.org/TR/json-ld11-api/#remote-document-and-context-retrieval so that custom JSON.LD.DocumentLoader implementations can reuse this by calling load/3 or implementing their own loading logic.

Custom HTTP clients

The default Tesla-based HTTP client is JSON.LD.DocumentLoader.DefaultClient.

If you need a custom HTTP client with custom middleware, you can create your own module that implements a client/3 function:

defmodule MyCustomClient do
  use Tesla

  def client(headers, url, options) do
    [
      {Tesla.Middleware.Headers, headers},
      # your custom middleware
    ]
    |> Tesla.client()
  end
end

and configure it as:

config :json_ld, :http_client, MyCustomClient

Summary

Types

t()

@type t() :: %JSON.LD.DocumentLoader.RemoteDocument{
  content_type: String.t(),
  context_url: String.t() | nil,
  document: any(),
  document_url: String.t(),
  profile: String.t() | nil
}

Functions

default_http_client()

http_get(http_client, url, options)

load(url, options \\ [], http_client \\ default_http_client())

@spec load(String.t(), JSON.LD.Options.convertible(), module()) ::
  {:ok, t()} | {:error, any()}

Loads a remote document from the given URL.

According to https://www.w3.org/TR/json-ld11-api/#remote-document-and-context-retrieval

load!(url, options \\ [], http_client \\ default_http_client())