Packages
A practical web framework for Gleam
Security advisory:
This version has known vulnerabilities.
View advisories
Current section
Files
Jump to
Current section
Files
README.md
[](https://hex.pm/packages/wisp)[](https://hexdocs.pm/wisp/)Wisp is a practical Gleam web framework rapid development and easy maintenance.We worry about the hassle of web development, and you focus on writing yourapplication.It is based around two concepts: handlers and middleware.# HandlersA handler is a function that takes a HTTP request and returns a HTTPresponse. A handler may also take other arguments, such as a "context" typedefined in your application which may hold other state such as a databaseconnection or user session.```gleamimport wisp.{Request, Response}pub type Context { Context(secret: String)}pub fn handle_request(request: Request, context: Context) -> Response { wisp.ok()}```# MiddlewareA middleware is a function that takes a response returning function as itslast argument, and itself returns a response. As with handlers bothmiddleware and the functions they take as an argument may take otherarguments.Middleware can be applied in a handler with Gleam's `use` syntax. Here the`log_request` middleware is used to log a message for each HTTP requesthandled, and the `serve_static` middleware is used to serve static filessuch as images and CSS.```gleamimport wisp.{Request, Response}pub fn handle_request(request: Request) -> Response { use <- wisp.log_request use <- wisp.serve_static(request, under: "/static", from: "/public") wisp.ok()}```# Learning WispThe Wisp examples are a good place to start. They cover various scenarios andinclude comments and tests.- [Hello, World!](https://github.com/lpil/wisp/tree/main/examples/0-hello-world)- [Routing](https://github.com/lpil/wisp/tree/main/examples/1-routing)- [Working with form data](https://github.com/lpil/wisp/tree/main/examples/2-working-with-form-data)- [Working with JSON](https://github.com/lpil/wisp/tree/main/examples/3-working-with-json)- [Working with other formats](https://github.com/lpil/wisp/tree/main/examples/4-working-with-other-formats)- [Using a database](https://github.com/lpil/wisp/tree/main/examples/5-using-a-database)- [Serving static assets](https://github.com/lpil/wisp/tree/main/examples/6-serving-static-assets)- [Logging](https://github.com/lpil/wisp/tree/main/examples/7-logging)- [Working with cookies](https://github.com/lpil/wisp/tree/main/examples/8-working-with-cookies)- [Configuring default responses](https://github.com/lpil/wisp/tree/main/examples/9-configuring-default-responses)API documentation is available on [HexDocs](https://hexdocs.pm/wisp/).# Wisp applicationsThese open source Wisp applications may be useful examples.- [https://packages.gleam.run/](https://github.com/gleam-lang/packages): A HTML serving application that uses an SQLite + LiteFS database, deployed to Fly.io.