cloudevents v0.1.0 Cloudevents View Source

Cloudevents implementation for Elixir. This is the main module.

Link to this section Summary

Functions

Converts a HTTP request into one or more Cloudevents.

Decodes a JSON-encoded Cloudevent.

Serialize an event in HTTP binary content mode.

Encodes a Cloudevents using JSON format.

Serialize an event in HTTP structured content mode.

Link to this section Types

Link to this section Functions

Link to this function

from_http_message(http_body, http_headers)

View Source
from_http_message(http_body(), http_headers()) ::
  {:ok, [cloudevent()]} | {:error, Cloudevents.ParseError.t()}

Converts a HTTP request into one or more Cloudevents.

Note that the HTTP request could contain more than one event (called a "batch"). Because of this, the function always returns a list of Cloudevents. Use pattern matching if you expect single events only:

with {:ok, [the_event]} = from_http_message(body, headers) do
  "do something with the_event"
else
  {:ok, events} -> "oops got a batch of events"
  {:error, error} -> "failed to parse HTTP request: #{inspect(error)}"
end
Link to this function

from_json(json)

View Source
from_json(json :: binary()) ::
  {:ok, cloudevent()}
  | {:error,
     %Cloudevents.Format.Decoder.DecodeError{
       __exception__: term(),
       cause: term()
     }}

Decodes a JSON-encoded Cloudevent.

Link to this function

to_binary_http_message(event)

View Source
to_binary_http_message(cloudevent()) :: {http_body(), http_headers()}

Serialize an event in HTTP binary content mode.

Link to this function

to_json(cloudevent)

View Source
to_json(cloudevent()) :: binary()

Encodes a Cloudevents using JSON format.

Link to this function

to_structured_http_message(event, event_format)

View Source
to_structured_http_message(cloudevent(), event_format :: :json) ::
  {http_body(), http_headers()}

Serialize an event in HTTP structured content mode.