Skip to content

Latest commit

 

History

History
388 lines (248 loc) · 7.38 KB

Handler.md

File metadata and controls

388 lines (248 loc) · 7.38 KB

Module Node.Express.Handler

HandlerM

data HandlerM e a

Monad responsible for handling single request.

Instances
instance functorHandlerM :: Functor (HandlerM e)
instance applyHandlerM :: Apply (HandlerM e)
instance applicativeHandlerM :: Applicative (HandlerM e)
instance bindHandlerM :: Bind (HandlerM e)
instance monadHandlerM :: Monad (HandlerM e)
instance monadEffHandlerM :: MonadEff eff (HandlerM eff)
instance monadAffHandlerM :: MonadAff eff (HandlerM eff)

Handler

type Handler e = HandlerM (express :: EXPRESS | e) Unit

runHandlerM

runHandlerM :: forall e. Handler e -> Request -> Response -> ExpressM e Unit -> ExpressM e Unit

next

next :: forall e. Handler e

Call next handler/middleware in a chain.

nextThrow

nextThrow :: forall e a. Error -> HandlerM (express :: EXPRESS | e) a

Call next handler/middleware and pass error to it.

getRouteParam

getRouteParam :: forall e a. (RequestParam a) => a -> HandlerM (express :: EXPRESS | e) (Maybe String)

getBodyParam

getBodyParam :: forall e a. (IsForeign a) => String -> HandlerM (express :: EXPRESS | e) (Maybe a)

Get param from request's body. NOTE: Not parsed by default, you must attach proper middleware See http://expressjs.com/4x/api.html#req.body

getQueryParam

getQueryParam :: forall e. String -> HandlerM (express :: EXPRESS | e) (Maybe String)

Get param from query string (part of URL behind '?'). If there are multiple params having equal keys return the first one.

getQueryParams

getQueryParams :: forall e. String -> HandlerM (express :: EXPRESS | e) (Array String)

Get all params from query string having specified key.

getRoute

getRoute :: forall e. HandlerM (express :: EXPRESS | e) String

Return route that matched this request.

getCookie

getCookie :: forall e. String -> HandlerM (express :: EXPRESS | e) (Maybe String)

Get cookie param by its key.

getSignedCookie

getSignedCookie :: forall e. String -> HandlerM (express :: EXPRESS | e) (Maybe String)

Get signed cookie param by its key.

getRequestHeader

getRequestHeader :: forall e. String -> HandlerM (express :: EXPRESS | e) (Maybe String)

Get request header param.

accepts

accepts :: forall e. String -> HandlerM (express :: EXPRESS | e) (Maybe String)

Check if specified response type will be accepted by a client.

ifAccepts

ifAccepts :: forall e. String -> Handler e -> Handler e

Execute specified handler if client accepts specified response type.

acceptsCharset

acceptsCharset :: forall e. String -> HandlerM (express :: EXPRESS | e) (Maybe String)

Check if specified charset is accepted.

acceptsLanguage

acceptsLanguage :: forall e. String -> HandlerM (express :: EXPRESS | e) (Maybe String)

Check if specified language is accepted.

hasType

hasType :: forall e. String -> HandlerM (express :: EXPRESS | e) Boolean

Check if request's Content-Type field matches type. See http://expressjs.com/4x/api.html#req.is

getRemoteIp

getRemoteIp :: forall e. HandlerM (express :: EXPRESS | e) String

Return remote or upstream address.

getRemoteIps

getRemoteIps :: forall e. HandlerM (express :: EXPRESS | e) (Array String)

Return list of X-Forwarded-For proxies if any.

getPath

getPath :: forall e. HandlerM (express :: EXPRESS | e) String

Return request URL pathname.

getHostname

getHostname :: forall e. HandlerM (express :: EXPRESS | e) String

Return Host header field.

getSubdomains

getSubdomains :: forall e. HandlerM (express :: EXPRESS | e) (Array String)

Return array of subdomains.

isFresh

isFresh :: forall e. HandlerM (express :: EXPRESS | e) Boolean

Check that Last-Modified and/or ETag still matches.

isStale

isStale :: forall e. HandlerM (express :: EXPRESS | e) Boolean

Check that Last-Modified and/or ETag do not match.

isXhr

isXhr :: forall e. HandlerM (express :: EXPRESS | e) Boolean

Check if request was issued by XMLHttpRequest.

getProtocol

getProtocol :: forall e. HandlerM (express :: EXPRESS | e) (Maybe Protocol)

Return request protocol.

getMethod

getMethod :: forall e. HandlerM (express :: EXPRESS | e) (Maybe Method)

Return request HTTP method

getUrl

getUrl :: forall e. HandlerM (express :: EXPRESS | e) String

Return request URL (may be modified by other handlers/middleware).

getOriginalUrl

getOriginalUrl :: forall e. HandlerM (express :: EXPRESS | e) String

Return request original URL.

setStatus

setStatus :: forall e. Int -> Handler e

getResponseHeader

getResponseHeader :: forall e a. (IsForeign a) => String -> HandlerM (express :: EXPRESS | e) (Maybe a)

Return response header value.

setResponseHeader

setResponseHeader :: forall e a. String -> a -> Handler e

Set response header value.

headersSent

headersSent :: forall e. HandlerM (express :: EXPRESS | e) Boolean

Check if headers have been sent already

setCookie

setCookie :: forall e. String -> String -> CookieOptions -> Handler e

Set cookie by its name using specified options (maxAge, path, etc).

clearCookie

clearCookie :: forall e. String -> String -> Handler e

Clear cookie.

send

send :: forall e a. a -> Handler e

Send a response. Could be object, string, buffer, etc.

sendJson

sendJson :: forall e a. a -> Handler e

Send a JSON response. Necessary headers are set automatically.

sendJsonp

sendJsonp :: forall e a. a -> Handler e

Send a JSON response with JSONP support.

redirect

redirect :: forall e. String -> Handler e

Redirect to the given URL setting status to 302.

redirectWithStatus

redirectWithStatus :: forall e. Int -> String -> Handler e

Redirect to the given URL using custom status.

setLocation

setLocation :: forall e. String -> Handler e

Set Location header.

setContentType

setContentType :: forall e. String -> Handler e

Set Content-Type header.

sendFile

sendFile :: forall e. String -> Handler e

Send file by its path.

sendFileExt

sendFileExt :: forall e o. String -> {  | o } -> (Error -> ExpressM e Unit) -> Handler e

Send file by its path using specified options and error handler. See http://expressjs.com/4x/api.html#res.sendfile

download

download :: forall e. String -> Handler e

Transfer file as an attachment (will prompt user to download).

downloadExt

downloadExt :: forall e. String -> String -> (Error -> ExpressM e Unit) -> Handler e

Transfer file as an attachment using specified filename and error handler.