Packages

A simple and easy to use API created on top of the Mist web server

Current section

Files

Jump to
howdy src howdy@response.erl
Raw

src/howdy@response.erl

-module(howdy@response).
-compile(no_auto_import).
-export([of_empty/0, of_string/1, of_bit_string/1, of_not_found/1, of_interal_error/1, of_json/1, with_status/2, with_header/3, with_content_type/2, with_accepted/1, with_created/1]).
-spec of_empty() -> gleam@http@response:response(binary()).
of_empty() ->
gleam@http@response:new(200).
-spec of_string(binary()) -> gleam@http@response:response(gleam@bit_builder:bit_builder()).
of_string(Text) ->
Body = gleam@bit_builder:from_string(Text),
_pipe = gleam@http@response:new(200),
gleam@http@response:set_body(_pipe, Body).
-spec of_bit_string(bitstring()) -> gleam@http@response:response(gleam@bit_builder:bit_builder()).
of_bit_string(Content) ->
Body = gleam@bit_builder:from_bit_string(Content),
_pipe = gleam@http@response:new(200),
gleam@http@response:set_body(_pipe, Body).
-spec of_not_found(binary()) -> gleam@http@response:response(any()).
of_not_found(Text) ->
_pipe = of_string(Text),
with_status(_pipe, 404).
-spec of_interal_error(binary()) -> gleam@http@response:response(any()).
of_interal_error(Text) ->
_pipe = of_string(Text),
with_status(_pipe, 500).
-spec of_json(gleam@json:json()) -> gleam@http@response:response(gleam@bit_builder:bit_builder()).
of_json(Json) ->
_pipe = of_string(gleam@json:to_string(Json)),
with_content_type(_pipe, howdy@mime:from_extention(<<"json"/utf8>>)).
-spec with_status(gleam@http@response:response(GVI), integer()) -> gleam@http@response:response(GVI).
with_status(Response, Status) ->
erlang:setelement(2, Response, Status).
-spec with_header(
gleam@http@response:response(gleam@bit_builder:bit_builder()),
binary(),
binary()
) -> gleam@http@response:response(gleam@bit_builder:bit_builder()).
with_header(Response, Key, Value) ->
gleam@http@response:prepend_header(Response, Key, Value).
-spec with_content_type(
gleam@http@response:response(gleam@bit_builder:bit_builder()),
binary()
) -> gleam@http@response:response(gleam@bit_builder:bit_builder()).
with_content_type(Response, Content_type) ->
_pipe = Response,
with_header(_pipe, <<"Content-Type"/utf8>>, Content_type).
-spec with_accepted(
gleam@http@response:response(gleam@bit_builder:bit_builder())
) -> gleam@http@response:response(gleam@bit_builder:bit_builder()).
with_accepted(Response) ->
_pipe = Response,
with_status(_pipe, 202).
-spec with_created(
gleam@http@response:response(gleam@bit_builder:bit_builder())
) -> gleam@http@response:response(gleam@bit_builder:bit_builder()).
with_created(Response) ->
_pipe = Response,
with_status(_pipe, 201).