lfe-http / lanes

A slightly more general HTTP routing library than LFE's lfest
Other
7 stars 1 forks source link

Add Cowboy support #4

Open oubiwann opened 3 years ago

oubiwann commented 3 years ago

Tasks:

Part of:

oubiwann commented 3 years ago

Cowboy routes:

Dispatch = cowboy_router:compile([
    %% {HostMatch, list({PathMatch, Handler, InitialState})}
    {'_', [{'_', my_handler, #{}}]}
]),
%% Name, TransOpts, ProtoOpts
cowboy:start_clear(my_http_listener,
    [{port, 8080}],
    #{env => #{dispatch => Dispatch}}
).

Cowboy routes in LFE:

(defun routes ()
  "Format: #(host-pattern (#(path-pattern handler state-0)))"
  '(#(_ (#(_ my-handler #m()))))

(defun dispatch ()
  (cowboy_router:compile (routes)))

(cowboy:start_clear 'my_http_listener
                    '(#(port 8080))
                    `#m(env #m(dispatch ,(dispatch))))

So I think ... really all that's needed is something to generate the routes function / data structure above ...