Skip to content

Request

Incoming HTTP request. Often referred to as req parameter.

Constructor

This section is empty.

Properties

incomingMessage

Type: readonly http.IncomingMessage

Underlying http.IncomingMessage object. Can be used to access lower-level API of the http Node.js module.

originalUrl

Type: readonly string

Original URL of the incoming request.

query

Type: readonly Record<string, string | string[] | undefined>

Request query, often referred to as “search params”.

body

Type: string | Record<string, any> | undefined

Body of the incoming request. undefined by default. To read the body, use one of the following middlewares:

If request body content type is text/plain, this field is a string, otherwise - Record<string, any>.

cookies

Type: Record<string, string> | undefined

Cookies of the incoming request. undefined by default. Use Cookie parser middleware to read cookies.

files

Type: Record<string, UploadedFile[]> | undefined

Files uploaded via a multipart/form-data form. undefined by default. Use Form parser middleware to read uploaded files.

headers

Type: http.IncomingHttpHeaders

Headers of the incoming message.

method

Type: HttpMethod

Method of incoming request.

params

Type: Record<string, string | string[]>

Request parameters, parsed from dynamic paths.

path

Type: string

Request path inside the context of the current Router.

import { LunaticServer, Router } from '@shelepuginivan/lunatic'
const app = new LunaticServer()
const router = new Router()
router.get('/some-path', (req, res) => {
console.log(req.path) // '/some-path', not '/router/some-path'
res.status(204).end()
})
app.use('/router', router)
app.get('/app', (req, res) => {
console.log(req.path) // '/app'
res.status(204).end()
})
app.get('/longer/path/', (req, res) => {
console.log(req.path) // '/longer/path/'
res.status(204).end()
})

protocol

Type: 'http' | 'https'

Protocol of the incoming request.

Methods

This section is empty.