Learn R Programming

RestRserve (version 0.1.5)

RestRserveMiddleware: Creates RestRserveMiddleware

Description

Creates RestRserveMiddleware object. RestRserveMiddleware is a very useful concept which allows to perform pre-processing 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 hadnler and response can be post processed (for example this way we developer can set up custom error messages). process_request and process_response functions should return forward() or RestRserveResponse. In the former scenario request, response will be passed further to subsequent middleware/handlers. In the later scenario the normal flow will be immediately interrupter and result of the function will be returned as response.

Usage

RestRserveMiddleware

Format

R6Class object.

Usage

  • app = RestRserveMiddleware$new( process_request = function(request, response) forward(), process_response = function(request, response) forward(), name = NULL )

For usage details see Methods, Arguments and Examples sections.

Arguments

process_request

function which takes 2 arguments - request and response objects (class RestRserveRequest and RestRserveResponse correspondingly) and returns forward() or RestRserveResponse. 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 (of class RestRserveRequest, and RestRserveResponse correspondingly) and returns forward() or RestRserveResponse. Function is called after request is processed by handler. Usually process_response is used to perform logging, custom error hadnling, etc.