Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

Commit

Permalink
Have barista serve up something! yeah.
Browse files Browse the repository at this point in the history
  • Loading branch information
wmealing committed Oct 28, 2023
1 parent 47c6789 commit 1feaefd
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/barista-routes.lfe
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(defmodule barista-routes
(export
(do 1)
(handle 3)))


(defun do (httpd-req)
(let ((req (barista-request:->map httpd-req)))
(handle (list_to_atom (mref req 'method))
(mref req 'path)
req)))


(defun handle
((method path (= `#m(body ,body) req))
"Example handler that displays whatever is passed through."
(lfe_io:format "method: ~p~n" (list method))
(lfe_io:format "path: ~p~n" (list path))
(let* ((headers '("Content-Type: text/plain"
"Cache-Control: no-cache"
"Cache-Control: no-store"
"\r\n"))
(body "hey there!\r\n"))
(lfe_io:format "headers: ~p~n" `(,headers))
(lfe_io:format "body: ~p~n~n" `(,body))
(barista:response 200 headers body))))

25 changes: 25 additions & 0 deletions src/barista-server-app.lfe
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
(defmodule barista-server-app
(behaviour application)
(export all))

(defun config ()
'(#(port 5098)
#(server_name "barista-server-app")
#(modules (barista-routes))))

(defun start ()
(barista:start (config))
(: timer sleep 'infinity)
)

(defun start (_type _args)
(start))

(defun stop (pid)
(barista:stop pid))

(defun stop ()
(inets:stop 'httpd))

(defun main (args)
(start))

0 comments on commit 1feaefd

Please sign in to comment.