webgear-server-0.1.0: Composable, type-safe library to build HTTP API servers
Copyright(c) Raghu Kaippully 2020
LicenseMPL-2.0
Maintainerrkaippully@gmail.com
Safe HaskellNone
LanguageHaskell2010

WebGear.Middlewares.Path

Description

Middlewares related to route paths.

Synopsis

Documentation

path :: forall s ts res m a. (KnownSymbol s, MonadRouter m) => RequestMiddleware m ts (Path s ': ts) res a Source #

A middleware that literally matches path s.

The symbol s could contain one or more parts separated by a forward slash character. The route will be rejected if there is no match.

For example, the following code could be used to match the URL path "a/b/c" and then invoke handler:

path @"a/b/c" handler

pathVar :: forall tag val ts res m a. (FromHttpApiData val, MonadRouter m) => RequestMiddleware m ts (PathVar tag val ': ts) res a Source #

A middleware that captures a path variable from a single path component.

The value captured is converted to a value of type val via FromHttpApiData. The route will be rejected if the value is not found or cannot be converted.

For example, the following code could be used to read a path component as Int tagged with the symbol "objId", and then invoke handler:

pathVar @"objId" @Int handler

match :: QuasiQuoter Source #

Produces middleware(s) to match an optional HTTP method and path.

This quasiquoter can be used in several ways:

  • [match|a/b/c] is equivalent to path @"a/b/c"
  • [match|a/b/objId:Int/d] is equivalent to path @"a/b" . pathVar @"objId" @Int . path "d"@
  • [match|GET a/b/c] is equivalent to method @GET $ path @"a/b/c"
  • [match|GET a/b/objId:Int/d] is equivalent to method @GET . path @"a/b" . pathVar @"objId" @Int . path @"d"