diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index faf24cc..cefc371 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,11 +10,11 @@ jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2.0.0 - - uses: erlef/setup-beam@v1.15.2 + - uses: actions/checkout@v4 + - uses: erlef/setup-beam@v1 with: - otp-version: "25.0" - gleam-version: "0.25.3" + otp-version: "26.0" + gleam-version: "1.0.0" rebar3-version: "3" - - run: gleam format --check src test - run: gleam test + - run: gleam format --check src test diff --git a/gleam.toml b/gleam.toml index 6b2aeeb..b962d52 100644 --- a/gleam.toml +++ b/gleam.toml @@ -1,4 +1,4 @@ -name = "echo" +name = "reply" version = "1.0.0" licences = ["Apache-2.0"] description = "A tiny echo server written in Gleam!" @@ -10,10 +10,10 @@ links = [ ] [dependencies] -gleam_stdlib = "~> 0.25" +gleam_stdlib = "~> 0.25 or ~> 1.0" gleam_http = "~> 3.0" gleam_elli = "~> 2.0" gleam_erlang = "~> 0.17" [dev-dependencies] -gleeunit = "~> 0.1" +gleeunit = "~> 1.0" diff --git a/manifest.toml b/manifest.toml index d8b6e6a..6b4aa98 100644 --- a/manifest.toml +++ b/manifest.toml @@ -3,17 +3,17 @@ packages = [ { name = "elli", version = "3.3.0", build_tools = ["rebar3"], requirements = [], otp_app = "elli", source = "hex", outer_checksum = "698B13B33D05661DB9FE7EFCBA41B84825A379CCE86E486CF6AFF9285BE0CCF8" }, - { name = "gleam_elli", version = "2.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_otp", "elli", "gleam_http"], otp_app = "gleam_elli", source = "hex", outer_checksum = "5DB2D8F83DF2A7384C5F381CCC837042EFB00272E9E5A01A071CC7600E2D6978" }, - { name = "gleam_erlang", version = "0.17.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "BAAA84F5BCC4477E809BA3E03BB3009A3894A6544C1511626C44408E39DB2AE6" }, - { name = "gleam_http", version = "3.1.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "B66B7A1539CCB577119E4DC80DD3484C1A652CB032967954498EEDBAE3355763" }, - { name = "gleam_otp", version = "0.5.2", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_erlang"], otp_app = "gleam_otp", source = "hex", outer_checksum = "24B88BF1D5B8DEC2525C00ECB65B96D2FD4DC66D8B2BB4D7AD4D12B2CE2A9988" }, - { name = "gleam_stdlib", version = "0.25.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "AD0F89928E0B919C8F8EDF640484633B28DBF88630A9E6AE504617A3E3E5B9A2" }, - { name = "gleeunit", version = "0.8.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "A1170754BF54F5DD6E9EF392FB1DC612528B007CCBE41B52F0C5453254708490" }, + { name = "gleam_elli", version = "2.4.0", build_tools = ["gleam"], requirements = ["elli", "gleam_erlang", "gleam_http", "gleam_otp", "gleam_stdlib"], otp_app = "gleam_elli", source = "hex", outer_checksum = "433F5AF4ED92C55F3EBA8942610E974254EEF90F484AF26E3D775E33338DE832" }, + { name = "gleam_erlang", version = "0.25.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "054D571A7092D2A9727B3E5D183B7507DAB0DA41556EC9133606F09C15497373" }, + { name = "gleam_http", version = "3.6.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "8C07DF9DF8CC7F054C650839A51C30A7D3C26482AC241C899C1CEA86B22DBE51" }, + { name = "gleam_otp", version = "0.10.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "0B04FE915ACECE539B317F9652CAADBBC0F000184D586AAAF2D94C100945D72B" }, + { name = "gleam_stdlib", version = "0.36.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "C0D14D807FEC6F8A08A7C9EF8DFDE6AE5C10E40E21325B2B29365965D82EB3D4" }, + { name = "gleeunit", version = "1.0.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "D364C87AFEB26BDB4FB8A5ABDE67D635DC9FA52D6AB68416044C35B096C6882D" }, ] [requirements] -gleam_elli = "~> 2.0" -gleam_erlang = "~> 0.17" -gleam_http = "~> 3.0" -gleam_stdlib = "~> 0.25" -gleeunit = "~> 0.1" +gleam_elli = { version = "~> 2.0" } +gleam_erlang = { version = "~> 0.17" } +gleam_http = { version = "~> 3.0" } +gleam_stdlib = { version = "~> 0.25 or ~> 1.0" } +gleeunit = { version = "~> 1.0" } diff --git a/src/echo.gleam b/src/reply.gleam similarity index 93% rename from src/echo.gleam rename to src/reply.gleam index 5374ed4..9d29683 100644 --- a/src/echo.gleam +++ b/src/reply.gleam @@ -1,11 +1,11 @@ -import echo/web -import gleam/io -import gleam/int -import gleam/string -import gleam/result -import gleam/erlang/process import gleam/erlang/os +import gleam/erlang/process import gleam/http/elli +import gleam/int +import gleam/io +import gleam/result +import gleam/string +import reply/web pub fn main() { let port = @@ -14,7 +14,7 @@ pub fn main() { |> result.unwrap(3000) // Start the web server process - assert Ok(_) = + let assert Ok(_) = web.stack() |> elli.start(on_port: port) diff --git a/src/echo/web.gleam b/src/reply/web.gleam similarity index 79% rename from src/echo/web.gleam rename to src/reply/web.gleam index 4671018..029a6af 100644 --- a/src/echo/web.gleam +++ b/src/reply/web.gleam @@ -1,14 +1,14 @@ -import gleam/bit_builder -import gleam/bit_string -import gleam/result -import gleam/string +import gleam/bit_array +import gleam/bytes_builder import gleam/http.{Get, Post} -import gleam/http/service import gleam/http/request import gleam/http/response -import echo/web/logger +import gleam/http/service +import gleam/result +import gleam/string +import reply/web/logger -fn echo(request) { +fn reply(request) { let content_type = request |> request.get_header("content-type") @@ -22,7 +22,7 @@ fn echo(request) { fn not_found() { let body = "There's nothing here. Try POSTing to /echo" - |> bit_string.from_string + |> bit_array.from_string response.new(404) |> response.set_body(body) @@ -36,7 +36,7 @@ fn hello(name) { } response.new(200) - |> response.set_body(bit_string.from_string(reply)) + |> response.set_body(bit_array.from_string(reply)) |> response.prepend_header("content-type", "text/plain") } @@ -44,7 +44,7 @@ pub fn service(request) { let path = request.path_segments(request) case request.method, path { - Post, ["echo"] -> echo(request) + Post, ["echo"] -> reply(request) Get, ["hello", name] -> hello(name) _, _ -> not_found() } @@ -53,6 +53,6 @@ pub fn service(request) { pub fn stack() { service |> service.prepend_response_header("made-with", "Gleam") - |> service.map_response_body(bit_builder.from_bit_string) + |> service.map_response_body(bytes_builder.from_bit_array) |> logger.middleware } diff --git a/src/echo/web/logger.gleam b/src/reply/web/logger.gleam similarity index 84% rename from src/echo/web/logger.gleam rename to src/reply/web/logger.gleam index a2ee1e8..f4f86d0 100644 --- a/src/echo/web/logger.gleam +++ b/src/reply/web/logger.gleam @@ -1,7 +1,7 @@ import gleam/http -import gleam/http/request.{Request} -import gleam/http/response.{Response} -import gleam/http/service.{Service} +import gleam/http/request.{type Request} +import gleam/http/response.{type Response} +import gleam/http/service.{type Service} import gleam/int import gleam/io import gleam/string diff --git a/test/echo/web_test.gleam b/test/reply/web_test.gleam similarity index 67% rename from test/echo/web_test.gleam rename to test/reply/web_test.gleam index ad761d4..22ac1da 100644 --- a/test/echo/web_test.gleam +++ b/test/reply/web_test.gleam @@ -1,7 +1,7 @@ -import echo/web import gleam/http.{Get, Post} import gleam/http/request import gleam/http/response +import reply/web pub fn not_found_test() { let resp = @@ -11,8 +11,8 @@ pub fn not_found_test() { |> request.set_body(<<>>) |> web.service() - assert 404 = resp.status - assert <<"There's nothing here. Try POSTing to /echo":utf8>> = resp.body + let assert 404 = resp.status + let assert <<"There's nothing here. Try POSTing to /echo":utf8>> = resp.body } pub fn hello_nubi_test() { @@ -23,8 +23,8 @@ pub fn hello_nubi_test() { |> request.set_body(<<>>) |> web.service() - assert 200 = resp.status - assert <<"Hello, Nubi!":utf8>> = resp.body + let assert 200 = resp.status + let assert <<"Hello, Nubi!":utf8>> = resp.body } pub fn hello_joe_test() { @@ -35,8 +35,8 @@ pub fn hello_joe_test() { |> request.set_body(<<>>) |> web.service() - assert 200 = resp.status - assert <<"Hello, Joe!":utf8>> = resp.body + let assert 200 = resp.status + let assert <<"Hello, Joe!":utf8>> = resp.body } pub fn echo_1_test() { @@ -48,9 +48,9 @@ pub fn echo_1_test() { |> request.prepend_header("content-type", "application/octet-stream") |> web.service() - assert 200 = resp.status - assert <<1, 2, 3, 4>> = resp.body - assert Ok("application/octet-stream") = + let assert 200 = resp.status + let assert <<1, 2, 3, 4>> = resp.body + let assert Ok("application/octet-stream") = response.get_header(resp, "content-type") } @@ -63,9 +63,9 @@ pub fn echo_2_test() { |> request.prepend_header("content-type", "text/plain") |> web.service() - assert 200 = resp.status - assert <<"Hello, Gleam!":utf8>> = resp.body - assert Ok("text/plain") = response.get_header(resp, "content-type") + let assert 200 = resp.status + let assert <<"Hello, Gleam!":utf8>> = resp.body + let assert Ok("text/plain") = response.get_header(resp, "content-type") } pub fn echo_3_test() { @@ -76,8 +76,8 @@ pub fn echo_3_test() { |> request.set_body(<<"Hello, Gleam!":utf8>>) |> web.service() - assert 200 = resp.status - assert <<"Hello, Gleam!":utf8>> = resp.body - assert Ok("application/octet-stream") = + let assert 200 = resp.status + let assert <<"Hello, Gleam!":utf8>> = resp.body + let assert Ok("application/octet-stream") = response.get_header(resp, "content-type") } diff --git a/test/echo_test.gleam b/test/reply_test.gleam similarity index 100% rename from test/echo_test.gleam rename to test/reply_test.gleam