JaSerializer.ContentTypeNegotiation

This plug provides content type negotiation by validating the content-type and accept headers.

The proper jsonapi.org content type is: application/vnd.api+json.

As per the spec this plug does three things.

  1. Returns 415 unless the content-type header is correct.
  2. Returns 406 unless the accept header is correct.
  3. Registers a before send hook to set the content-type if not already set.

Usage

Just include in your plug stack:

plug JaSerializer.ContentTypeNegotiation
Source

Summary

call(conn, opts)

Callback implementation for c:Plug.call/2

init(opts)

Callback implementation for c:Plug.init/1

set_content_type(conn, opts)
verify_accepts(conn, opts)
verify_content_type(conn, o)

Functions

call(conn, opts)

Callback implementation for c:Plug.call/2.

Source
init(opts)

Callback implementation for c:Plug.init/1.

Source
set_content_type(conn, opts)
Source
verify_accepts(conn, opts)
Source
verify_content_type(conn, o)
Source