🧚 A practical web framework for Gleam

README!

Changed files
+47 -48
src
+47 -1
README.md
··· 3 3 [![Package Version](https://img.shields.io/hexpm/v/wisp)](https://hex.pm/packages/wisp) 4 4 [![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/wisp/) 5 5 6 - A Gleam project 🧚 6 + Wisp is a practical Gleam web framework rapid development and easy maintenance. 7 + We worry about the hassle of web development, and you focus on writing your 8 + application. 9 + 10 + It is based around two concepts: handlers and middleware. 11 + 12 + # Handlers 13 + 14 + A handler is a function that takes a HTTP request and returns a HTTP 15 + response. A handler may also take other arguments, such as a "context" type 16 + defined in your application which may hold other state such as a database 17 + connection or user session. 18 + 19 + ```gleam 20 + import wisp.{Request, Response} 21 + 22 + pub type Context { 23 + Context(secret: String) 24 + } 25 + 26 + pub fn handle_request(request: Request, context: Context) -> Response { 27 + wisp.ok() 28 + } 29 + ``` 30 + 31 + # Middleware 32 + 33 + A middleware is a function that takes a response returning function as its 34 + last argument, and itself returns a response. As with handlers both 35 + middleware and the functions they take as an argument may take other 36 + arguments. 37 + 38 + Middleware can be applied in a handler with Gleam's `use` syntax. Here the 39 + `log_request` middleware is used to log a message for each HTTP request 40 + handled, and the `serve_static` middleware is used to serve static files 41 + such as images and CSS. 42 + 43 + ```gleam 44 + import wisp.{Request, Response} 45 + 46 + pub fn handle_request(request: Request) -> Response { 47 + use <- wisp.log_request 48 + use <- wisp.serve_static(req, under: "/static", from: "/public") 49 + wisp.ok() 50 + } 51 + ``` 52 +
-47
src/wisp.gleam
··· 1 - /// Wisp! A Gleam web framework. 2 - /// 3 - /// ## Overview 4 - /// 5 - /// Wisp is based around two concepts: handlers and middleware. 6 - /// 7 - /// ### Handlers 8 - /// 9 - /// A handler is a function that takes a HTTP request and returns a HTTP 10 - /// response. A handler may also take other arguments, such as a "context" type 11 - /// defined in your application which may hold other state such as a database 12 - /// connection or user session. 13 - /// 14 - /// ```gleam 15 - /// import wisp.{Request, Response} 16 - /// 17 - /// pub type Context { 18 - /// Context(secret: String) 19 - /// } 20 - /// 21 - /// pub fn handle_request(request: Request, context: Context) -> Response { 22 - /// wisp.ok() 23 - /// } 24 - /// ``` 25 - /// 26 - /// ### Middleware 27 - /// 28 - /// A middleware is a function that takes a response returning function as its 29 - /// last argument, and itself returns a response. As with handlers both 30 - /// middleware and the functions they take as an argument may take other 31 - /// arguments. 32 - /// 33 - /// Middleware can be applied in a handler with Gleam's `use` syntax. Here the 34 - /// `log_request` middleware is used to log a message for each HTTP request 35 - /// handled, and the `serve_static` middleware is used to serve static files 36 - /// such as images and CSS. 37 - /// 38 - /// ```gleam 39 - /// import wisp.{Request, Response} 40 - /// 41 - /// pub fn handle_request(request: Request) -> Response { 42 - /// use <- wisp.log_request 43 - /// use <- wisp.serve_static(req, under: "/static", from: "/public") 44 - /// wisp.ok() 45 - /// } 46 - /// ``` 47 - /// 48 1 import gleam/string_builder.{StringBuilder} 49 2 import gleam/bit_builder.{BitBuilder} 50 3 import gleam/bit_string