Skip to content

Commit

Permalink
Add routing example using bell
Browse files Browse the repository at this point in the history
  • Loading branch information
ccfontes authored Nov 6, 2023
1 parent a24c37d commit ab37f9e
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 3 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/faas_fn_build_invoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,13 @@ jobs:
if [ "$(docker exec bb-http-map-context curl -X POST -d '{"foo": "bar", "spam": "eggs"}' -H 'content-type: application/json' --retry 3 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082)" != '[["foo","spam"],["bar","eggs"],"application/json","http://127.0.0.1:8082"]' ]; then
exit 7
fi
(docker stop bb-routes-bell || exit 0)
(docker rm bb-routes-bell || exit 0)
docker run -d --name bb-routes-bell ghcr.io/${{ github.repository_owner }}/bb-routes-bell:latest bb --main index
if [ "$(docker exec bb-routes-bell curl -X POST -d '{"foo": "bar"}' -H 'content-type: application/json' --retry 3 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082)" != '[["foo"],["bar"]]' ]; then
exit 8
fi
if [ "$(docker exec bb-routes-bell curl -X PUT --retry 3 --retry-delay 2 --retry-connrefused http://127.0.0.1:8082/foo/123)" != '[["id"],["123"]]' ]; then
exit 9
fi
3 changes: 1 addition & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ In `bb-streaming` language:
----
(defn handler [event] ...)
----
The `event` is the payload body, and the function return is the payload body for the response.

The `event` is extracted from the HTTP payload body, and the function return is used as the HTTP payload body for the response.

== link:examples[Function examples]

Expand Down
2 changes: 2 additions & 0 deletions examples/http/bb-routes-bell/bb.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{:paths ["."]
:deps {net.tessellator/bell {:mvn/version "0.2.0"}}}
11 changes: 11 additions & 0 deletions examples/http/bb-routes-bell/handler.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(ns function.handler
(:require [bell.core :refer [router POST PUT]]))

(def handler
(router
(POST "/"
(fn [{:keys [body]}]
[(keys body) (vals body)]))
(PUT "/foo/:id"
(fn [{:keys [path-params]}]
[(keys path-params) (vals path-params)]))))
4 changes: 4 additions & 0 deletions examples/stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ functions:
image: ${DOCKER_REGISTRY_IMG_ORG_PATH}/bb-http-map-context
environment:
keywords: true
bb-routes-bell:
lang: bb
handler: ./http/bb-routes-bell
image: ${DOCKER_REGISTRY_IMG_ORG_PATH}/bb-routes-bell
1 change: 1 addition & 0 deletions template/bb/bb.edn
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
; used only for tests. Not copied into docker container
{:paths ["." "lib"]
:deps {eg/eg {:mvn/version "0.5.6-alpha"}}}
1 change: 0 additions & 1 deletion template/bb/index.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
[ring.middleware.json :refer [wrap-json-body]]
[ring.middleware.text :refer [wrap-text-body]]
[ring.middleware.headers :refer [wrap-lowercase-headers wrap-friendly-headers]]
[ring.middleware.headers]
[ring.util.walk :as ring-walk]
[compojure.response :as response]
[function.handler :as function]))
Expand Down

0 comments on commit ab37f9e

Please sign in to comment.