View Source HttpStatus protocol (HttpStatus v0.1.0)
HttpStatus protocol implemented for Integer, BitString (strings) and Atom
Summary
Types
@type t() :: term()
All the types that implement this protocol.
Functions
Converts a protocol implementation to a HTTP status represented as an atom value.
Implemented for Integer and BitString (String)
Examples
iex> HttpStatus.to_atom(200)
:ok
iex> HttpStatus.to_atom(404)
:not_found
iex> HttpStatus.to_atom("OK")
:ok
iex> HttpStatus.to_atom("Not Found")
:not_found
@spec to_code(t()) :: pos_integer()
Converts a protocol implementation to a HTTP status represented as an integer value.
Implemented for Atom and BitString (String)
Examples
iex> HttpStatus.to_code(:ok)
200
iex> HttpStatus.to_code(:not_found)
404
iex> HttpStatus.to_code("OK")
200
iex> HttpStatus.to_code("Not Found")
404
Converts a protocol implementation to a HTTP status represented as a String value.
Implemented for Atom and Integer
Examples
iex> HttpStatus.to_string(200)
"OK"
iex> HttpStatus.to_string(404)
"Not Found"
iex> HttpStatus.to_string(:ok)
"OK"
iex> HttpStatus.to_string(:not_found)
"Not Found"