Module

Yoga.HTTP.API.Route.Handler

Package
purescript-yoga-http-api
Repository
rowtype-yoga/purescript-yoga-http-api

#HandlerFn Source

type HandlerFn :: Row Type -> Row Type -> Row Type -> Type -> Row Type -> Typetype HandlerFn pathParams queryParams reqHeaders body respVariant = { body :: body, headers :: Record reqHeaders, path :: Record pathParams, query :: Record queryParams } -> Aff (Variant respVariant)

Type-safe handler tied to a route's computed types.

Usage: myHandler :: Handler (id :: Int) (limit :: Maybe Int) (authorization :: BearerToken) User (ok :: ResponseData () (Array Post), notFound :: ResponseData () ErrorMessage) myHandler { path, query, headers, body } = do -- path :: { id :: Int } -- query :: { limit :: Maybe Int } -- headers :: { authorization :: BearerToken } -- body :: User pure $ respondNoHeaders (Proxy :: _ "ok") []

#Request Source

data Request r

Constructors

#NoRequest Source

type NoRequest = Record ()

Type alias for routes with no request data (no headers, cookies, or body).

Usage: Route GET "health" NoRequest (ok :: { body :: String })

Equivalent to: Route GET "health" {} (ok :: { body :: String })

#DefaultRequestFields Source

class DefaultRequestFields :: Row Type -> Row Type -> Row Type -> Type -> Constraintclass DefaultRequestFields (partialRequest :: Row Type) (fullHeaders :: Row Type) (fullCookies :: Row Type) (fullEncoding :: Type) | partialRequest -> fullHeaders fullCookies fullEncoding

Compute defaults for missing request fields using RowList.

When a Request omits headers, defaults to (). When a Request omits cookies, defaults to (). When a Request omits body, defaults to NoBody.

Instances

#DefaultRequestFieldsRL Source

class DefaultRequestFieldsRL :: RowList Type -> Row Type -> Row Type -> Row Type -> Type -> Constraintclass DefaultRequestFieldsRL (rl :: RowList Type) (partialRequest :: Row Type) (fullHeaders :: Row Type) (fullCookies :: Row Type) (fullEncoding :: Type) | rl partialRequest -> fullHeaders fullCookies fullEncoding

RowList-based implementation

Instances

#SegmentPathParams Source

class SegmentPathParams :: forall k. k -> Row Type -> Constraintclass SegmentPathParams segments params | segments -> params

Extract the row of typed path parameters from a path segments type.

Instances

#SegmentQueryParams Source

class SegmentQueryParams :: forall k. k -> Row Type -> Constraintclass SegmentQueryParams segments query | segments -> query

Extract the row of typed query parameters from a path segments type.

Instances

#SegmentQueryParamsRL Source

class SegmentQueryParamsRL :: RowList Type -> Row Type -> Constraintclass SegmentQueryParamsRL (rl :: RowList Type) (query :: Row Type) | rl -> query

RowList-based processing of query param rows. Required ty → ty (plain), otherwise → Maybe ty

Instances

#EncodingBody Source

class EncodingBody (encoding :: Type) (body :: Type) | encoding -> body

Map encoding phantom types to the runtime body type the handler receives.

Instances

#CaptureParams Source

class CaptureParams :: forall k. k -> Row Type -> Constraintclass CaptureParams segs (params :: Row Type) | segs -> params

Walk the path segments and collect all Capture/Param entries into a row.

Instances

#RequestHeaders Source

class RequestHeaders :: Type -> Row Type -> Constraintclass RequestHeaders (request :: Type) (headers :: Row Type) | request -> headers

Extract the headers row from a request record type.

The request is expected to have a headers field.

Instances

#RequestCookies Source

class RequestCookies :: Type -> Row Type -> Constraintclass RequestCookies (request :: Type) (cookies :: Row Type) | request -> cookies

Extract the cookies row from a request record type.

The request is expected to have a cookies field.

Instances

#RequestBody Source

class RequestBody (request :: Type) (encoding :: Type) | request -> encoding

Extract the body encoding type from a request record type.

The request is expected to have a body field.

Instances