PgRest.MediaType (PgRest v0.2.0)

Copy Markdown View Source

One media type of an Accept header, as PostgREST understands it.

kind is what PgRest can answer: :json (application/json), :object (application/vnd.pgrst.object[+json]), :array (application/vnd.pgrst.array[+json]), :csv (text/csv), :plan (application/vnd.pgrst.plan[+json|+text]), :any (*/*) or :other. Matching is case-insensitive. raw is the type as the client wrote it with the q parameter dropped (it is what a PGRST107 lists). nulls_stripped? is the nulls=stripped parameter, valid on :array and :object only. plan is set for :plan: its format, the media type it is for (application/json when the client names none) and its options, in PostgREST's order (analyze, verbose, settings, buffers, wal). A plan's raw is PostgREST's canonical name for it, application/vnd.pgrst.plan+<format>; for="<type>" and ; options=<a>|<b> when there are any: what a PGRST107 lists and the response echoes.

Summary

Functions

The */* any type, what a missing Accept header means.

The media type a statement answers in: the type itself, application/json for */*, and for a plan the type it is for, so an explained statement is the one that would run for it.

The Content-Type of a response in this media type. The stripped types name the parameter as PostgREST does; an :array that is not stripped is plain JSON. Error bodies are always application/json.

The default, application/json.

Types

kind()

@type kind() :: :json | :object | :array | :csv | :plan | :any | :other

plan()

@type plan() :: %{format: :text | :json, for: t(), options: [plan_option()]}

plan_option()

@type plan_option() :: :analyze | :verbose | :settings | :buffers | :wal

t()

@type t() :: %PgRest.MediaType{
  kind: kind(),
  nulls_stripped?: boolean(),
  plan: plan() | nil,
  q: float(),
  raw: String.t()
}

Functions

any()

@spec any() :: t()

The */* any type, what a missing Accept header means.

body(media)

@spec body(t()) :: t()

The media type a statement answers in: the type itself, application/json for */*, and for a plan the type it is for, so an explained statement is the one that would run for it.

content_type(media_type)

@spec content_type(t()) :: String.t()

The Content-Type of a response in this media type. The stripped types name the parameter as PostgREST does; an :array that is not stripped is plain JSON. Error bodies are always application/json.

json()

@spec json() :: t()

The default, application/json.