diff --git a/README.md b/README.md index eae170f..f80f350 100644 --- a/README.md +++ b/README.md @@ -3,4 +3,50 @@ [![Package Version](https://img.shields.io/hexpm/v/wisp)](https://hex.pm/packages/wisp) [![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/wisp/) -A Gleam project 🧚 +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 your +application. + +It is based around two concepts: handlers and middleware. + +# Handlers + +A handler is a function that takes a HTTP request and returns a HTTP +response. A handler may also take other arguments, such as a "context" type +defined in your application which may hold other state such as a database +connection or user session. + +```gleam +import wisp.{Request, Response} + +pub type Context { + Context(secret: String) +} + +pub fn handle_request(request: Request, context: Context) -> Response { + wisp.ok() +} +``` + +# Middleware + +A middleware is a function that takes a response returning function as its +last argument, and itself returns a response. As with handlers both +middleware and the functions they take as an argument may take other +arguments. + +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 request +handled, and the `serve_static` middleware is used to serve static files +such as images and CSS. + +```gleam +import wisp.{Request, Response} + +pub fn handle_request(request: Request) -> Response { + use <- wisp.log_request + use <- wisp.serve_static(req, under: "/static", from: "/public") + wisp.ok() +} +``` + diff --git a/src/wisp.gleam b/src/wisp.gleam index ef126b3..e357abb 100644 --- a/src/wisp.gleam +++ b/src/wisp.gleam @@ -1,50 +1,3 @@ -/// Wisp! A Gleam web framework. -/// -/// ## Overview -/// -/// Wisp is based around two concepts: handlers and middleware. -/// -/// ### Handlers -/// -/// A handler is a function that takes a HTTP request and returns a HTTP -/// response. A handler may also take other arguments, such as a "context" type -/// defined in your application which may hold other state such as a database -/// connection or user session. -/// -/// ```gleam -/// import wisp.{Request, Response} -/// -/// pub type Context { -/// Context(secret: String) -/// } -/// -/// pub fn handle_request(request: Request, context: Context) -> Response { -/// wisp.ok() -/// } -/// ``` -/// -/// ### Middleware -/// -/// A middleware is a function that takes a response returning function as its -/// last argument, and itself returns a response. As with handlers both -/// middleware and the functions they take as an argument may take other -/// arguments. -/// -/// 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 request -/// handled, and the `serve_static` middleware is used to serve static files -/// such as images and CSS. -/// -/// ```gleam -/// import wisp.{Request, Response} -/// -/// pub fn handle_request(request: Request) -> Response { -/// use <- wisp.log_request -/// use <- wisp.serve_static(req, under: "/static", from: "/public") -/// wisp.ok() -/// } -/// ``` -/// import gleam/string_builder.{StringBuilder} import gleam/bit_builder.{BitBuilder} import gleam/bit_string