HTTP Handlers

This page summarizes how to properly use HTTP Handlers.

circle-info

Please see Mandarine MVC Controllersarrow-up-right before continuing.

How to properly use HTTP Handlers

HTTP handlers as we have mentioned before, are just methods that are decorated with route decorationarrow-up-right. Although, they can handle complex operations by using HTTP Parameter decorators.

HTTP Parameter Decorators

They are decorators that are used in the parameters of a HTTP Handler. Every decorator provides a different functionality, but the objective is the same for all of them: The interaction of the current request & your mandarine-powered web application.

  • @RouteParam(name?: string)

    • It will bring the value of the param declared on the route path. This value comes from the client's request.

    • name is used to identify what parameter from the route path we are trying to get

      • Optional

      • If name is ignored, then its value will be the parameter's key.

  • @QueryParam(name?: string)

    • It will bring the value of the desired query parameter. This value comes from the URL a client has requested.

    • name is used to identify what query parameter from the request's url we are trying to get

      • Optional

      • If name is ignored, then its value will be the parameter's key.

  • @RequestBody()

    • It will bring the value from request's body.

      • It is the equivalent to request.body()arrow-up-right.

      • Mandarine will try to parse it when the content type of the body is application/x-www-form-urlencoded or application/json . If the content-type is not known, the whole body object will be inject it instead.

  • @Session()

    • It will bring the current session object located in the request.

  • @Cookie(name?: string)

    • It will bring the cookie with the key name

    • name is used to identify what cookie from the request we are trying to get

      • Optional

      • If name is ignored, then its value will be the parameter's key.

  • @ServerRequestParam()

  • @RequestParam()

    • It will bring the all the information available from the request made by a client.

  • @ResponseParam()

    • It will bring the value from the current response given by the server before being delivered to the client.

    • Modifications to the request can and will affect the outcome of the response delivered to the client after the HTTP handler has been executed.

Usage

Request

Last updated