Middleware {RestRserve}R Documentation

Creates middleware object

Description

Creates Middleware object.

Middleware is a very useful concept which allows to perform preprocessing of requests and post-processing of responses. Middleware has an access to both request and response objects and can modify them. This way each request can be checked/modified before passing handler and response can be post processed (for example this way we developer can set up custom error messages).

Public fields

process_request

Function which takes 2 arguments - request and response objects (class Request and Response correspondingly) and modify request and response or throw exception using HTTPError helper.
Function is called before request is routed to handler.
Usually process_request is used to perform logging, check authorization, etc.

process_response

Function which takes 2 arguments - request and response objects (class Request and Response correspondingly) and modify request and response or throw exception using HTTPError helper.
Function is called after request is processed by handler. Usually process_response is used to perform logging, custom error handling, etc.

id

Middleware id.

Methods

Public methods


Method new()

Creates middleware object

Usage
Middleware$new(
  process_request = function(request, response) TRUE,
  process_response = function(request, response) TRUE,
  id = "Middleware"
)
Arguments
process_request

Modify request or response objects or throw exception using ⁠[HTTPError]⁠ helper. This function evaluate before router handler called.

process_response

Modify request or response objects or throw exception using ⁠[HTTPError]⁠ helper. This function evaluate after router handler called.

id

Middleware id.


Method clone()

The objects of this class are cloneable with this method.

Usage
Middleware$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

Request Response Application


[Package RestRserve version 1.2.3 Index]