All Downloads are FREE. Search and download functionalities are using the official Maven repository.

erlang-server.logic_handler.mustache Maven / Gradle / Ivy

There is a newer version: 7.9.0
Show newest version
-module({{packageName}}_logic_handler).

-export([handle_request/4]).
{{#authMethods}}
{{#isApiKey}}
{{#-first}}
-export([authorize_api_key/3]).
{{/-first}}
{{/isApiKey}}
{{/authMethods}}
{{^authMethods}}
-export([authorize_api_key/3]).
{{/authMethods}}
-type context() :: #{binary() => any()}.
-type handler_response() ::{
    Status :: cowboy:http_status(),
    Headers :: cowboy:http_headers(),
    Body :: jsx:json_term()}.

-export_type([handler_response/0]).

{{#authMethods}}
    {{#isApiKey}}
-callback authorize_api_key(
    OperationID :: {{packageName}}_api:operation_id(),
    ApiKey :: binary()
) ->
    Result :: boolean() | {boolean(), context()}.
    {{/isApiKey}}
{{/authMethods}}


-callback handle_request(OperationID :: {{packageName}}_api:operation_id(), cowboy_req:req(), Context :: context()) ->
    handler_response().

-spec handle_request(
    Handler :: atom(),
    OperationID :: {{packageName}}_api:operation_id(),
    Request :: cowboy_req:req(),
    Context :: context()
) ->
    handler_response().

handle_request(Handler, OperationID, Req, Context) ->
    Handler:handle_request(OperationID, Req, Context).

{{#authMethods}}
    {{#isApiKey}}
-spec authorize_api_key(Handler :: atom(), OperationID :: {{packageName}}_api:operation_id(), ApiKey :: binary()) ->
    Result :: false | {true, context()}.
authorize_api_key(Handler, OperationID, ApiKey) ->
    Handler:authorize_api_key(OperationID, ApiKey).
    {{/isApiKey}}
{{/authMethods}}
{{^authMethods}}
-spec authorize_api_key(Handler :: atom(), OperationID :: {{packageName}}_api:operation_id(), ApiKey :: binary()) ->
    Result :: false.
authorize_api_key(_Handler, _OperationID, _ApiKey) ->
    false.
{{/authMethods}}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy