Skip to content

API Request

Michael Anderson edited this page Dec 1, 2017 · 5 revisions

CoffeeCat API - Request Class

The Request class extends the Express Request class by adding additional properties.

Properties

applet

Type: Applet

This property holds a reference to the CoffeeCat applet to which this request has been routed.

Inherited Properties

app

Type: Express.Application

Express API

This property holds a reference to the instance of the Express application that is using the applet middleware. This is the same reference returned from applet.app

baseUrl

Type: string

Express API

The URL path on which the applet is mounted. Unlike Applet.configuration.applet.path which can contain wild cards, baseURL contains the requested value. e.g. If Applet.configuration.applet.path contains /gre+t, and a request is made to /greet/hello.html request.applet.configuration.applet.path will contain /gre+t, while baseURL will contain /greet.

body

Type: Object<string,string>

Express API

Contains key-value pairs of data submitted in the request body. By default, it is undefined, and is populated when you use body-parsing middleware.

cookies

Type: Object<string,string>

Express API

When using cookie-parser middleware, this property is an object that contains cookies sent by the request. If the request contains no cookies, it defaults to {}.

fresh

Type: boolean

Express API

Indicates if whether the request is "fresh".

hostname

Type: string

Express API

Contains the hostname derived from the Host HTTP header.

ip

Type: string

Express API

Contains the remote IP address of the request.

ips

Type: Array

Express API

Contains an array of IP addresses specified in the X-Forwarded-For request header, or an empty array.

method

Type: string

Express API

Contains a string corresponding to the HTTP method of the request.

originalUrl

Type: string

Express API

Contains the original request URL. This allows you to rewrite req.url for internal routing.

params

Type: Object<string,string>

Default: {}

Express API

This property is an object containing properties mapped to the named route "parameters".

Route parameters are especially helpful in generating "friendly" URLs. If a route is configured as follows:

router.get('/users/:userid', (req, res, next) => {
    ...
});

Then a request to /users/4532 will be populate the parameters object with { "userid": "4532" }. This format is cleaner for your users than /users?userid=4532

path

Type: string

Express API

Contains the path part of the request URL.

protocol

Type: string

Express API

Contains the request protocol string.

query

Type: Object<string,string>

Default: {}

Express API

This property is an object containing a property for each query string parameter in the route. If there is no query string, it is the empty object, {}.

Clone this wiki locally