···33[](https://hex.pm/packages/wisp)
44[](https://hexdocs.pm/wisp/)
5566-A Gleam project 🧚
66+Wisp is a practical Gleam web framework rapid development and easy maintenance.
77+We worry about the hassle of web development, and you focus on writing your
88+application.
99+1010+It is based around two concepts: handlers and middleware.
1111+1212+# Handlers
1313+1414+A handler is a function that takes a HTTP request and returns a HTTP
1515+response. A handler may also take other arguments, such as a "context" type
1616+defined in your application which may hold other state such as a database
1717+connection or user session.
1818+1919+```gleam
2020+import wisp.{Request, Response}
2121+2222+pub type Context {
2323+ Context(secret: String)
2424+}
2525+2626+pub fn handle_request(request: Request, context: Context) -> Response {
2727+ wisp.ok()
2828+}
2929+```
3030+3131+# Middleware
3232+3333+A middleware is a function that takes a response returning function as its
3434+last argument, and itself returns a response. As with handlers both
3535+middleware and the functions they take as an argument may take other
3636+arguments.
3737+3838+Middleware can be applied in a handler with Gleam's `use` syntax. Here the
3939+`log_request` middleware is used to log a message for each HTTP request
4040+handled, and the `serve_static` middleware is used to serve static files
4141+such as images and CSS.
4242+4343+```gleam
4444+import wisp.{Request, Response}
4545+4646+pub fn handle_request(request: Request) -> Response {
4747+ use <- wisp.log_request
4848+ use <- wisp.serve_static(req, under: "/static", from: "/public")
4949+ wisp.ok()
5050+}
5151+```
5252+
-47
src/wisp.gleam
···11-/// Wisp! A Gleam web framework.
22-///
33-/// ## Overview
44-///
55-/// Wisp is based around two concepts: handlers and middleware.
66-///
77-/// ### Handlers
88-///
99-/// A handler is a function that takes a HTTP request and returns a HTTP
1010-/// response. A handler may also take other arguments, such as a "context" type
1111-/// defined in your application which may hold other state such as a database
1212-/// connection or user session.
1313-///
1414-/// ```gleam
1515-/// import wisp.{Request, Response}
1616-///
1717-/// pub type Context {
1818-/// Context(secret: String)
1919-/// }
2020-///
2121-/// pub fn handle_request(request: Request, context: Context) -> Response {
2222-/// wisp.ok()
2323-/// }
2424-/// ```
2525-///
2626-/// ### Middleware
2727-///
2828-/// A middleware is a function that takes a response returning function as its
2929-/// last argument, and itself returns a response. As with handlers both
3030-/// middleware and the functions they take as an argument may take other
3131-/// arguments.
3232-///
3333-/// Middleware can be applied in a handler with Gleam's `use` syntax. Here the
3434-/// `log_request` middleware is used to log a message for each HTTP request
3535-/// handled, and the `serve_static` middleware is used to serve static files
3636-/// such as images and CSS.
3737-///
3838-/// ```gleam
3939-/// import wisp.{Request, Response}
4040-///
4141-/// pub fn handle_request(request: Request) -> Response {
4242-/// use <- wisp.log_request
4343-/// use <- wisp.serve_static(req, under: "/static", from: "/public")
4444-/// wisp.ok()
4545-/// }
4646-/// ```
4747-///
481import gleam/string_builder.{StringBuilder}
492import gleam/bit_builder.{BitBuilder}
503import gleam/bit_string