Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Response

Response class.

Hierarchy

  • Response

Implements

  • any

Index

Properties

app

body

headers

headers: Headers = new Headers()

locals

locals: any

req

req: Request

status

status: Status = 200

written

written: Boolean = false

Methods

append

  • append(field: string, value: string): this
  • Append additional header field with value val.

    Example:

    res.append('Set-Cookie', 'foo=bar; Path=/; HttpOnly'); res.append('Warning', '199 Miscellaneous warning');

    Parameters

    • field: string
    • value: string

    Returns this

    for chaining

attachment

  • attachment(filename: string): this
  • Set Content-Disposition header to attachment with optional filename.

    Parameters

    • filename: string

    Returns this

    for chaining

clearCookie

  • clearCookie(cookie: string | Cookie): this
  • Clear a cookie.

    Parameters

    Returns this

    for chaining

cookie

  • cookie(cookie: Cookie): this
  • Set a cookie. Sets the cookie path to "/" if not defined.

    Examples:

    // "Remember Me" for 15 minutes res.cookie({ name: "rememberme", value: "1", expires: new Date(Date.now() + 900000), httpOnly: true });

    Parameters

    Returns this

    for chaining

download

  • download(path: string, filename?: string): Promise<this | void>
  • Transfer the file at the given path as an attachment.

    Optionally providing an alternate attachment filename.

    This function will set the Content-Disposition header, overriding any existing Content-Disposition header in order to set the attachment and filename.

    This method uses res.sendFile().

    Parameters

    • path: string
    • Optional filename: string

    Returns Promise<this | void>

end

etag

  • etag(chunk: string | Uint8Array | Deno.FileInfo): this
  • Sets an ETag header.

    Parameters

    • chunk: string | Uint8Array | Deno.FileInfo

    Returns this

    for chaining

format

  • format(obj: any): this
  • Respond to the Acceptable formats using an obj of mime-type callbacks.

    This method uses req.accepted, an array of acceptable types ordered by their quality values. When "Accept" is not present the first callback is invoked, otherwise the first match is used. When no match is performed the server responds with 406 "Not Acceptable".

    Content-Type is set for you, however if you choose you may alter this within the callback using res.type() or res.set('Content-Type', ...).

    res.format({ 'text/plain': function(){ res.send('hey'); },

     'text/html': function(){
       res.send('<p>hey</p>');
     },
    
     'application/json': function(){
       res.send({ message: 'hey' });
     }

    });

    In addition to canonicalized MIME types you may also use extnames mapped to these types:

    res.format({ text: function(){ res.send('hey'); },

     html: function(){
       res.send('<p>hey</p>');
     },
    
     json: function(){
       res.send({ message: 'hey' });
     }

    });

    By default Express passes an Error with a .status of 406 to next(err) if a match is not made. If you provide a .default callback it will be invoked instead.

    Parameters

    • obj: any

    Returns this

    for chaining

get

  • get(field: string): string
  • Get value for header field.

    Parameters

    • field: string

    Returns string

    the header

json

  • Send JSON response.

    Examples:

    res.json(null);
    res.json({ user: 'deno' });

    Parameters

    Returns this

    for chaining

jsonp

  • Send JSON response with JSONP callback support.

    Examples:

    res.jsonp(null);
    res.jsonp({ user: 'deno' });

    Parameters

    Returns this

    for chaining

links

  • links(links: any): this

location

  • location(url: string): this
  • Set the location header to url.

    The given url can also be "back", which redirects to the Referrer or Referer headers or "/".

    Examples:

    res.location('/foo/bar').; res.location('http://example.com'); res.location('../login');

    Parameters

    • url: string

    Returns this

    for chaining

redirect

  • redirect(url: string): void
  • redirect(statusCode: Status, url: string): void
  • Redirect to the given url with optional response status defaulting to 302.

    The resulting url is determined by res.location().

    Examples:

    res.redirect('/foo/bar'); res.redirect('http://example.com'); res.redirect(301, 'http://example.com'); res.redirect('../login'); // /blog/post/1 -> /blog/login

    Parameters

    • url: string

    Returns void

  • Parameters

    • statusCode: Status
    • url: string

    Returns void

render

  • render(view: string, options?: any, callback?: any): void
  • Render view with the given options and optional callback fn. When a callback function is given a response will not be made automatically, otherwise a response of 200 and text/html is given.

    Options:

    • cache boolean hinting to the engine it should cache
    • filename filename of the view being rendered

    Parameters

    • view: string
    • Default value options: any = {}
    • Optional callback: any

    Returns void

send

  • Send a response.

    Examples:

    res.send({ some: 'json' });
    res.send('<p>some html</p>');

    Parameters

    Returns this

    for chaining

sendFile

  • sendFile(path: string): Promise<this | void>
  • Transfer the file at the given path.

    Automatically sets the Content-Type response header field.

    Parameters

    • path: string

    Returns Promise<this | void>

sendStatus

  • sendStatus(code: Status): this
  • Send given HTTP status code.

    Sets the response status to code and the body of the response to the standard description from deno's http_status.STATUS_TEXT or the code number if no description.

    Examples:

    res.sendStatus(200);

    Parameters

    • code: Status

    Returns this

    for chaining

set

  • set(field: string, value: string): this
  • set(obj: Record<string, string>): this
  • Set header field to value, or pass an object of header fields.

    Examples:

    res.set('Accept', 'application/json');
    res.set({
      'Accept-Language': "en-US, en;q=0.5",
      'Accept': 'text/html',
    });

    Parameters

    • field: string
    • value: string

    Returns this

    for chaining

  • Parameters

    • obj: Record<string, string>

    Returns this

setStatus

  • setStatus(code: Status): this
  • Set status code.

    This method deviates from Express due to the naming clash with Deno.Response status property.

    Parameters

    • code: Status

    Returns this

    for chaining

type

  • type(type: string): this
  • Set Content-Type response header with type.

    Examples:

    res.type('.html');
    res.type('html');
    res.type('json');
    res.type('application/json');
    res.type('png');

    Parameters

    • type: string

    Returns this

    for chaining

unset

  • unset(field: string): this
  • Deletes a header.

    Parameters

    • field: string

    Returns this

    for chaining

vary

  • vary(field: string | string[]): this
  • Add field to Vary. If already present in the Vary set, then this call is simply ignored.

    Parameters

    • field: string | string[]

    Returns this

    for chaining

Generated using TypeDoc