Skip to content

Commit 0905488

Browse files
author
Ryan Miville
committed
example
1 parent 978fa5d commit 0905488

File tree

10 files changed

+135
-4
lines changed

10 files changed

+135
-4
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ gleam add glambda
1818
```gleam
1919
import glambda.{type Context}
2020
import gleam/javascript/promise.{type Promise}
21-
import gleam/json
22-
import wisp.{type Request, type Reponse}
21+
import gleam/string_builder
22+
import wisp.{type Request, type Response}
2323
24-
fn handle_request(req: Request, ctx: Context) -> Promise(Response) {
24+
fn handle_request(_req: Request, ctx: Context) -> Promise(Response) {
2525
string_builder.from_string(
2626
"{\"functionName\": \"" <> ctx.function_name <> "\"}",
2727
)
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: test
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- main
8+
pull_request:
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: erlef/setup-beam@v1
16+
with:
17+
otp-version: "26.0.2"
18+
gleam-version: "1.5.1"
19+
rebar3-version: "3"
20+
# elixir-version: "1.15.4"
21+
- run: gleam deps download
22+
- run: gleam test
23+
- run: gleam format --check src test

examples/app/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.beam
2+
*.ez
3+
/build
4+
erl_crash.dump

examples/app/README.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# app
2+
3+
[![Package Version](https://img.shields.io/hexpm/v/app)](https://hex.pm/packages/app)
4+
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/app/)
5+
6+
```sh
7+
gleam add app@1
8+
```
9+
```gleam
10+
import app
11+
12+
pub fn main() {
13+
// TODO: An example of the project in use
14+
}
15+
```
16+
17+
Further documentation can be found at <https://hexdocs.pm/app>.
18+
19+
## Development
20+
21+
```sh
22+
gleam run # Run the project
23+
gleam test # Run the tests
24+
```

examples/app/gleam.toml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name = "handler"
2+
version = "1.0.0"
3+
target = "javascript"
4+
5+
[dependencies]
6+
gleam_stdlib = ">= 0.34.0 and < 2.0.0"
7+
glambda = { path = "../.." }
8+
wisp = ">= 1.2.0 and < 2.0.0"
9+
gleam_http = ">= 3.7.0 and < 4.0.0"
10+
gleam_javascript = ">= 0.13.0 and < 1.0.0"
11+
12+
[dev-dependencies]
13+
gleeunit = ">= 1.0.0 and < 2.0.0"

examples/app/manifest.toml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# This file was generated by Gleam
2+
# You typically do not need to edit this file
3+
4+
packages = [
5+
{ name = "birl", version = "1.7.1", build_tools = ["gleam"], requirements = ["gleam_stdlib", "ranger"], otp_app = "birl", source = "hex", outer_checksum = "5C66647D62BCB11FE327E7A6024907C4A17954EF22865FE0940B54A852446D01" },
6+
{ name = "directories", version = "1.1.0", build_tools = ["gleam"], requirements = ["envoy", "gleam_stdlib", "platform", "simplifile"], otp_app = "directories", source = "hex", outer_checksum = "BDA521A4EB9EE3A7894F0DC863797878E91FF5C7826F7084B2E731E208BDB076" },
7+
{ name = "envoy", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "envoy", source = "hex", outer_checksum = "CFAACCCFC47654F7E8B75E614746ED924C65BD08B1DE21101548AC314A8B6A41" },
8+
{ name = "exception", version = "2.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "exception", source = "hex", outer_checksum = "F5580D584F16A20B7FCDCABF9E9BE9A2C1F6AC4F9176FA6DD0B63E3B20D450AA" },
9+
{ name = "filepath", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "EFB6FF65C98B2A16378ABC3EE2B14124168C0CE5201553DE652E2644DCFDB594" },
10+
{ name = "glambda", version = "0.1.0", build_tools = ["gleam"], requirements = ["gleam_http", "gleam_javascript", "gleam_stdlib", "wisp"], source = "local", path = "../.." },
11+
{ name = "gleam_crypto", version = "1.4.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_crypto", source = "hex", outer_checksum = "8AE56026B3E05EBB1F076778478A762E9EB62B31AEEB4285755452F397029D22" },
12+
{ name = "gleam_erlang", version = "0.27.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "DE468F676D71B313C6C8C5334425CFCF827837333F8AB47B64D8A6D7AA40185D" },
13+
{ name = "gleam_http", version = "3.7.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "EA66440C2269F7CED0F6845E5BD0DB68095775D627FA709A841CA78A398D6D56" },
14+
{ name = "gleam_javascript", version = "0.13.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_javascript", source = "hex", outer_checksum = "F98328FCF573DA6F3A35D7F6CB3F9FF19FD5224CCBA9151FCBEAA0B983AF2F58" },
15+
{ name = "gleam_json", version = "2.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_json", source = "hex", outer_checksum = "CB10B0E7BF44282FB25162F1A24C1A025F6B93E777CCF238C4017E4EEF2CDE97" },
16+
{ name = "gleam_otp", version = "0.12.1", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "BFACC1513410DF5A1617169A9CD7EA334973AC71D860A17574BA7B2EADD89A6F" },
17+
{ name = "gleam_stdlib", version = "0.40.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "86606B75A600BBD05E539EB59FABC6E307EEEA7B1E5865AFB6D980A93BCB2181" },
18+
{ name = "gleeunit", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "F7A7228925D3EE7D0813C922E062BFD6D7E9310F0BEE585D3A42F3307E3CFD13" },
19+
{ name = "glisten", version = "6.0.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_otp", "gleam_stdlib", "logging", "telemetry"], otp_app = "glisten", source = "hex", outer_checksum = "912132751031473CB38F454120124FFC96AF6B0EA33D92C9C90DB16327A2A972" },
20+
{ name = "gramps", version = "2.0.3", build_tools = ["gleam"], requirements = ["gleam_crypto", "gleam_erlang", "gleam_http", "gleam_stdlib"], otp_app = "gramps", source = "hex", outer_checksum = "3CCAA6E081225180D95C79679D383BBF51C8D1FDC1B84DA1DA444F628C373793" },
21+
{ name = "hpack_erl", version = "0.3.0", build_tools = ["rebar3"], requirements = [], otp_app = "hpack", source = "hex", outer_checksum = "D6137D7079169D8C485C6962DFE261AF5B9EF60FBC557344511C1E65E3D95FB0" },
22+
{ name = "logging", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "logging", source = "hex", outer_checksum = "1098FBF10B54B44C2C7FDF0B01C1253CAFACDACABEFB4B0D027803246753E06D" },
23+
{ name = "marceau", version = "1.3.0", build_tools = ["gleam"], requirements = [], otp_app = "marceau", source = "hex", outer_checksum = "2D1C27504BEF45005F5DFB18591F8610FB4BFA91744878210BDC464412EC44E9" },
24+
{ name = "mist", version = "3.0.0", build_tools = ["gleam"], requirements = ["birl", "gleam_erlang", "gleam_http", "gleam_otp", "gleam_stdlib", "glisten", "gramps", "hpack_erl", "logging"], otp_app = "mist", source = "hex", outer_checksum = "CDA1A74E768419235E16886463EC4722EFF4AB3F8D820A76EAD45D7C167D7282" },
25+
{ name = "platform", version = "1.0.0", build_tools = ["gleam"], requirements = [], otp_app = "platform", source = "hex", outer_checksum = "8339420A95AD89AAC0F82F4C3DB8DD401041742D6C3F46132A8739F6AEB75391" },
26+
{ name = "ranger", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "ranger", source = "hex", outer_checksum = "1566C272B1D141B3BBA38B25CB761EF56E312E79EC0E2DFD4D3C19FB0CC1F98C" },
27+
{ name = "simplifile", version = "2.2.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "0DFABEF7DC7A9E2FF4BB27B108034E60C81BEBFCB7AB816B9E7E18ED4503ACD8" },
28+
{ name = "telemetry", version = "1.3.0", build_tools = ["rebar3"], requirements = [], otp_app = "telemetry", source = "hex", outer_checksum = "7015FC8919DBE63764F4B4B87A95B7C0996BD539E0D499BE6EC9D7F3875B79E6" },
29+
{ name = "wisp", version = "1.2.0", build_tools = ["gleam"], requirements = ["directories", "exception", "gleam_crypto", "gleam_erlang", "gleam_http", "gleam_json", "gleam_stdlib", "logging", "marceau", "mist", "simplifile"], otp_app = "wisp", source = "hex", outer_checksum = "F71265D2F1DE11426535A2FA1DA3B11D2FFB783B116DF9496BC8C41983EBADB4" },
30+
]
31+
32+
[requirements]
33+
glambda = { path = "../.." }
34+
gleam_http = { version = ">= 3.7.0 and < 4.0.0" }
35+
gleam_javascript = { version = ">= 0.13.0 and < 1.0.0" }
36+
gleam_stdlib = { version = ">= 0.34.0 and < 2.0.0" }
37+
gleeunit = { version = ">= 1.0.0 and < 2.0.0" }
38+
wisp = { version = ">= 1.2.0 and < 2.0.0" }

examples/app/src/handler.gleam

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import glambda.{type Context}
2+
import gleam/javascript/promise.{type Promise}
3+
import gleam/string_builder
4+
import wisp.{type Request, type Response}
5+
6+
pub fn handle_request(_req: Request, ctx: Context) -> Promise(Response) {
7+
string_builder.from_string(
8+
"{\"functionName\": \"" <> ctx.function_name <> "\"}",
9+
)
10+
|> wisp.json_response(200)
11+
|> promise.resolve
12+
}
13+
14+
pub fn handler(event, ctx) {
15+
glambda.wisp_handler(handle_request)(event, ctx)
16+
}

examples/app/test/handler_test.gleam

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import gleeunit
2+
3+
pub fn main() {
4+
gleeunit.main()
5+
}

src/glambda.gleam

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ pub fn wisp_handler(
192192
})
193193
}
194194

195-
fn create_request(event: ApiGatewayProxyEventV2) -> Request {
195+
pub fn create_request(event: ApiGatewayProxyEventV2) -> Request {
196196
let read = case event.body {
197197
Some(body) ->
198198
internal.Chunk(bit_array.from_string(body), fn(_size) {

test/glambda_test.gleam

+8
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ pub fn api_gateway_v2_http_response_valid_empty_fields_test() {
9696
|> birdie.snap("API Gateway V2 HTTP Response with valid empty fields")
9797
}
9898

99+
// pub fn wisp_request_test() {
100+
// js_event("./test/testdata/apigw-v2-request-jwt-authorizer.json")
101+
// |> glambda.to_api_gateway_proxy_event_v2
102+
// |> glambda.create_request
103+
// |> format
104+
// |> birdie.snap("Wisp request from API Gateway V2 HTTP request with JWT authorizer")
105+
// }
106+
99107
pub fn format(value: a) -> String {
100108
pprint.with_config(value, Config(Unstyled, BitArraysAsString, Labels))
101109
}

0 commit comments

Comments
 (0)