Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Response

OpineResponse class.

Hierarchy

  • Response

Implements

Index

Properties

Private #resources

#resources: number[] = []

app

body

headers

headers: Headers = new Headers()

locals

locals: any

req

status

status: Status = 200

written

written: boolean = false

Methods

addResource

  • addResource(rid: number): void

append

  • append(field: string, value: string | string[]): this
  • Append additional header field with value val. Value can be either a string or an array of string.

    Example:

    res.append('Set-Cookie', 'foo=bar; Path=/; HttpOnly'); res.append('Warning', '199 Miscellaneous warning'); res.append("cache-control", ["public", "max-age=604800", "immutable"]);

    Parameters

    • field: string
    • value: string | string[]

    Returns this

    for chaining

attachment

  • attachment(filename: string): this

clearCookie

cookie

  • cookie(name: string, value: string, options: CookieOptions): this
  • cookie(cookie: Cookie): this

download

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

    Optionally providing an alternate attachment filename.

    Optionally providing an options object to use with res.sendFile().

    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
    • Optional options: any

    Returns Promise<this | void>

end

etag

  • etag(chunk: string | Uint8Array | Deno.FileInfo): this

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

json

jsonp

links

  • links(links: any): this

location

  • location(url: string): this

redirect

  • redirect(url: string): void
  • redirect(statusCode: Status, url: string): void

removeHeader

  • removeHeader(field: string): this

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

sendFile

  • sendFile(path: string, options?: any): 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

setHeader

  • setHeader(field: string, value: string): this
  • setHeader(obj: Record<string, string>): this

setStatus

  • setStatus(code: Status): this

type

  • type(type: string): this

unset

  • unset(field: string): this

vary

  • vary(field: string | string[]): this

Generated using TypeDoc