Module

Nodetrout.Internal.Request

Package
purescript-nodetrout
Repository
nsaunders/purescript-nodetrout

This module contains various request-processing functionality that would otherwise clutter the Router module and increase its coupling to the Node server (bad for testability).

#Request Source

newtype Request

A Request contains the request method, URL, and headers, as well as an Aff that reads the request body, which are used in the routing logic. Since this library is only interested in building a Node server, this abstraction really only exists to help test routing logic.

Constructors

Instances

#headerValue Source

headerValue :: String -> Request -> Maybe String

Attempts to get the value from a request header.

#method Source

method :: Request -> Either Method CustomMethod

Gets and parses the request method.

#path Source

path :: Request -> Array String

Gets and parses the request path (URL).

#queryParamValue Source

queryParamValue :: String -> Request -> Maybe String

Gets the first value from the query string matching the specified label (key). For example, given a label of foo and a request with a query string of ?foo=bar&foo=baz, this would return a string "bar".

#queryParamValues Source

queryParamValues :: String -> Request -> Array String

Gets all values from the query string matching the specified label (key). For example, given a label of foo and a request with a query string of ?foo=bar&foo=baz, this would return an array ["bar", "baz"].

#removePath Source

removePath :: Request -> Tuple (Array String) Request

Captures the remaining segments from the request path and returns them along with a scoped request. Useful when routing the request.

#stringBody Source

stringBody :: Request -> Aff (Maybe String)

Gets the request body as a string.

#unconsPath Source

unconsPath :: Request -> Tuple (Maybe String) Request

Gets the next segment from the request path if available and returns it along with a scoped request. Useful when routing the request.