2012-01-23 12:42:04 -06:00
|
|
|
-module(rest_forbidden_resource).
|
|
|
|
-export([init/3, rest_init/2, allowed_methods/2, forbidden/2,
|
|
|
|
content_types_provided/2, content_types_accepted/2,
|
2013-04-11 17:59:54 +02:00
|
|
|
to_text/2, from_text/2]).
|
2012-01-23 12:42:04 -06:00
|
|
|
|
|
|
|
init(_Transport, _Req, _Opts) ->
|
2012-08-27 13:39:59 +02:00
|
|
|
{upgrade, protocol, cowboy_rest}.
|
2012-01-23 12:42:04 -06:00
|
|
|
|
|
|
|
rest_init(Req, [Forbidden]) ->
|
2012-01-23 20:17:00 +01:00
|
|
|
{ok, Req, Forbidden}.
|
2012-01-23 12:42:04 -06:00
|
|
|
|
|
|
|
allowed_methods(Req, State) ->
|
2012-09-20 06:22:51 +02:00
|
|
|
{[<<"GET">>, <<"HEAD">>, <<"POST">>], Req, State}.
|
2012-01-23 12:42:04 -06:00
|
|
|
|
|
|
|
forbidden(Req, State=true) ->
|
|
|
|
{true, Req, State};
|
|
|
|
forbidden(Req, State=false) ->
|
|
|
|
{false, Req, State}.
|
|
|
|
|
|
|
|
content_types_provided(Req, State) ->
|
|
|
|
{[{{<<"text">>, <<"plain">>, []}, to_text}], Req, State}.
|
|
|
|
|
|
|
|
content_types_accepted(Req, State) ->
|
|
|
|
{[{{<<"text">>, <<"plain">>, []}, from_text}], Req, State}.
|
|
|
|
|
|
|
|
to_text(Req, State) ->
|
|
|
|
{<<"This is REST!">>, Req, State}.
|
|
|
|
|
|
|
|
from_text(Req, State) ->
|
2013-04-11 17:59:54 +02:00
|
|
|
{Path, Req2} = cowboy_req:path(Req),
|
|
|
|
{Path, Req2, State}.
|