🧚 A practical web framework for Gleam

Example!

+104 -1
+24
examples/0-hello-world/README.md
··· 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 + A Gleam project 7 + 8 + ## Quick start 9 + 10 + ```sh 11 + gleam run # Run the project 12 + gleam test # Run the tests 13 + gleam shell # Run an Erlang shell 14 + ``` 15 + 16 + ## Installation 17 + 18 + If available on Hex this package can be added to your Gleam project: 19 + 20 + ```sh 21 + gleam add app 22 + ``` 23 + 24 + and its documentation can be found at <https://hexdocs.pm/app>.
+10
examples/0-hello-world/gleam.toml
··· 1 + name = "app" 2 + version = "1.0.0" 3 + description = "A Wisp example" 4 + 5 + [dependencies] 6 + gleam_stdlib = "~> 0.30" 7 + wisp = { path = "../.." } 8 + 9 + [dev-dependencies] 10 + gleeunit = "~> 0.10"
+19
examples/0-hello-world/manifest.toml
··· 1 + # This file was generated by Gleam 2 + # You typically do not need to edit this file 3 + 4 + packages = [ 5 + { name = "gleam_erlang", version = "0.20.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "F216A80C8FDFF774447B494D5E08AE4E9A911E971727B9A78FEBF5F300914584" }, 6 + { name = "gleam_http", version = "3.5.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "FAE9AE3EB1CA90C2194615D20FFFD1E28B630E84DACA670B28D959B37BCBB02C" }, 7 + { name = "gleam_otp", version = "0.6.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_erlang"], otp_app = "gleam_otp", source = "hex", outer_checksum = "E31B158857E3D2AF946FE6E90E0CB21699AF226F4630E93FBEAC5DB4515F8920" }, 8 + { name = "gleam_stdlib", version = "0.30.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "03710B3DA047A3683117591707FCA19D32B980229DD8CE8B0603EB5B5144F6C3" }, 9 + { name = "gleeunit", version = "0.10.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "ECEA2DE4BE6528D36AFE74F42A21CDF99966EC36D7F25DEB34D47DD0F7977BAF" }, 10 + { name = "glisten", version = "0.8.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_otp", "gleam_erlang"], otp_app = "glisten", source = "hex", outer_checksum = "6DDE276F8A2E3C79E5A580DEA05C7D87FCDE3A37FF69F607770D92686E193531" }, 11 + { name = "mist", version = "0.13.1", build_tools = ["gleam"], requirements = ["gleam_http", "glisten", "gleam_stdlib", "gleam_erlang"], otp_app = "mist", source = "hex", outer_checksum = "178EDF5F396570DD53BE2A94C8F9759072093DACB81B62CD47A620B961DB2F2D" }, 12 + { name = "simplifile", version = "0.1.8", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "9CED66E65AF32C98AA336A65365A498DCF018D2A3D96A05D861C4005DCDE4D2D" }, 13 + { name = "wisp", version = "0.1.0", build_tools = ["gleam"], requirements = ["gleam_http", "gleam_stdlib", "mist", "simplifile"], source = "local", path = "/Users/louis/src/gleam/wisp" }, 14 + ] 15 + 16 + [requirements] 17 + gleam_stdlib = { version = "~> 0.30" } 18 + gleeunit = { version = "~> 0.10" } 19 + wisp = { path = "../.." }
+35
examples/0-hello-world/src/app.gleam
··· 1 + import gleam/string_builder 2 + import gleam/erlang/process 3 + import mist 4 + import wisp 5 + 6 + /// The HTTP request handler- your application! 7 + pub fn handle_request(req: wisp.Request) -> wisp.Response { 8 + use _req <- middleware(req) 9 + let body = string_builder.from_string("<h1>Hello, Joe!</h1>") 10 + wisp.html_response(body, 200) 11 + } 12 + 13 + /// The middleware stack that the request handler uses. 14 + pub fn middleware( 15 + req: wisp.Request, 16 + service: fn(wisp.Request) -> wisp.Response, 17 + ) -> wisp.Response { 18 + let req = wisp.method_override(req) 19 + use <- wisp.log_requests(req) 20 + use <- wisp.rescue_crashes 21 + 22 + service(req) 23 + } 24 + 25 + /// Lastly, the main function that runs the service using the Mist HTTP server. 26 + pub fn main() { 27 + let assert Ok(_) = 28 + wisp.mist_service(handle_request) 29 + |> mist.new 30 + |> mist.port(8000) 31 + |> mist.start_http 32 + 33 + // Mist runs in new Erlang process, so put this one to sleep. 34 + process.sleep_forever() 35 + }
+12
examples/0-hello-world/test/app_test.gleam
··· 1 + import gleeunit 2 + import gleeunit/should 3 + 4 + pub fn main() { 5 + gleeunit.main() 6 + } 7 + 8 + // gleeunit test functions end in `_test` 9 + pub fn hello_world_test() { 10 + 1 11 + |> should.equal(1) 12 + }
+4 -1
src/wisp.gleam
··· 864 864 pub fn delete_temporary_files( 865 865 request: Request, 866 866 ) -> Result(Nil, simplifile.FileError) { 867 - simplifile.delete_directory(request.body.temporary_directory) 867 + case simplifile.delete_directory(request.body.temporary_directory) { 868 + Error(simplifile.Enoent) -> Ok(Nil) 869 + other -> other 870 + } 868 871 } 869 872 870 873 @external(erlang, "file", "read_file_info")