Skip to content

crelte / server / ServerRequest

Class: ServerRequest ​

Extended Request class for server requests

This extends the WebApi Request and adds three properties site, getParam and siteMatches.

Extends ​

  • Request

Constructors ​

Constructor ​

ts
new ServerRequest(
   inner, 
   params, 
   site): ServerRequest;

Parameters ​

inner ​

Request

params ​

Map<string, string>

site ​

Site

Returns ​

ServerRequest

Overrides ​

ts
Request.constructor

Properties ​

body ​

ts
readonly body: ReadableStream<Uint8Array<ArrayBuffer>> | null;

MDN Reference

Inherited from ​

ts
Request.body

bodyUsed ​

ts
readonly bodyUsed: boolean;

MDN Reference

Inherited from ​

ts
Request.bodyUsed

cache ​

ts
readonly cache: RequestCache;

The cache read-only property of the Request interface contains the cache mode of the request.

MDN Reference

Inherited from ​

ts
Request.cache

credentials ​

ts
readonly credentials: RequestCredentials;

The credentials read-only property of the Request interface reflects the value given to the Request.Request() constructor in the credentials option.

MDN Reference

Inherited from ​

ts
Request.credentials

destination ​

ts
readonly destination: RequestDestination;

The destination read-only property of the Request interface returns a string describing the type of content being requested.

MDN Reference

Inherited from ​

ts
Request.destination

headers ​

ts
readonly headers: Headers;

The headers read-only property of the with the request.

MDN Reference

Inherited from ​

ts
Request.headers

integrity ​

ts
readonly integrity: string;

The integrity read-only property of the Request interface contains the subresource integrity value of the request.

MDN Reference

Inherited from ​

ts
Request.integrity

keepalive ​

ts
readonly keepalive: boolean;

The keepalive read-only property of the Request interface contains the request's keepalive setting (true or false), which indicates whether the browser will keep the associated request alive if the page that initiated it is unloaded before the request is complete.

MDN Reference

Inherited from ​

ts
Request.keepalive

method ​

ts
readonly method: string;

The method read-only property of the POST, etc.) A String indicating the method of the request.

MDN Reference

Inherited from ​

ts
Request.method

mode ​

ts
readonly mode: RequestMode;

The mode read-only property of the Request interface contains the mode of the request (e.g., cors, no-cors, same-origin, or navigate.) This is used to determine if cross-origin requests lead to valid responses, and which properties of the response are readable.

MDN Reference

Inherited from ​

ts
Request.mode

redirect ​

ts
readonly redirect: RequestRedirect;

The redirect read-only property of the Request interface contains the mode for how redirects are handled.

MDN Reference

Inherited from ​

ts
Request.redirect

referrer ​

ts
readonly referrer: string;

The referrer read-only property of the Request.

MDN Reference

Inherited from ​

ts
Request.referrer

referrerPolicy ​

ts
readonly referrerPolicy: ReferrerPolicy;

The referrerPolicy read-only property of the referrer information, sent in the Referer header, should be included with the request.

MDN Reference

Inherited from ​

ts
Request.referrerPolicy

signal ​

ts
readonly signal: AbortSignal;

The read-only signal property of the Request interface returns the AbortSignal associated with the request.

MDN Reference

Inherited from ​

ts
Request.signal

site ​

ts
site: Site;

The site of the route

Note ​

The site might not always match with the current route but be the site default site or one that matches the users language.

If that is important call req.siteMatches() to verify


url ​

ts
readonly url: string;

The url read-only property of the Request interface contains the URL of the request.

MDN Reference

Inherited from ​

ts
Request.url

Methods ​

arrayBuffer() ​

ts
arrayBuffer(): Promise<ArrayBuffer>;

MDN Reference

Returns ​

Promise<ArrayBuffer>

Inherited from ​

ts
Request.arrayBuffer

blob() ​

ts
blob(): Promise<Blob>;

MDN Reference

Returns ​

Promise<Blob>

Inherited from ​

ts
Request.blob

bytes() ​

ts
bytes(): Promise<Uint8Array<ArrayBuffer>>;

MDN Reference

Returns ​

Promise<Uint8Array<ArrayBuffer>>

Inherited from ​

ts
Request.bytes

clone() ​

ts
clone(): Request;

The clone() method of the Request interface creates a copy of the current Request object.

MDN Reference

Returns ​

Request

Inherited from ​

ts
Request.clone

formData() ​

ts
formData(): Promise<FormData>;

MDN Reference

Returns ​

Promise<FormData>

Inherited from ​

ts
Request.formData

getParam() ​

ts
getParam(name): string | null;

returns the url params from the request

Parameters ​

name ​

string

Returns ​

string | null

Example ​

js
router.get('/blog/:slug', async csr => {
    return Response.json({ slug: csr.req.getParam('slug') });
});

json() ​

ts
json(): Promise<any>;

MDN Reference

Returns ​

Promise<any>

Inherited from ​

ts
Request.json

siteMatches() ​

ts
siteMatches(): boolean;

Returns if the site matches the url

Returns ​

boolean


text() ​

ts
text(): Promise<string>;

MDN Reference

Returns ​

Promise<string>

Inherited from ​

ts
Request.text