Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface IMeshResponse

Wrapper for the express.Response. We can use them to add properties to the response.

Hierarchy

  • Response
    • IMeshResponse

Implements

  • EventEmitter
  • WritableStream

Index

Constructors

constructor

Properties

charset

charset: string

headersSent

headersSent: boolean

json

json: Send

Send JSON response.

Examples:

res.json(null);
res.json({ user: 'tj' });
res.json(500, 'oh noes!');
res.json(404, 'I dont have that');

jsonp

jsonp: Send

Send JSON response with JSONP callback support.

Examples:

res.jsonp(null);
res.jsonp({ user: 'tj' });
res.jsonp(500, 'oh noes!');
res.jsonp(404, 'I dont have that');

locals

locals: any

send

send: Send

Send a response.

Examples:

res.send(new Buffer('wahoo'));
res.send({ some: 'json' });
res.send('<p>some html</p>');
res.send(404, 'Sorry, cant find that');
res.send(404);

sendDate

sendDate: boolean

statusCode

statusCode: number

writable

writable: boolean

Methods

_write

  • _write(data: Buffer, encoding: string, callback: Function): void
  • _write(data: string, encoding: string, callback: Function): void

addListener

  • addListener(event: string, listener: Function): EventEmitter

addTrailers

  • addTrailers(headers: any): void

attachment

  • attachment(filename?: string): Response

clearCookie

  • clearCookie(name: string, options?: any): Response

contentType

  • contentType(type: string): Response
  • Set Content-Type response header with type through mime.lookup() when it does not contain "/", or set the Content-Type to type otherwise.

    Examples:

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

    Parameters

    • type: string

    Returns Response

cookie

  • cookie(name: string, val: string, options: CookieOptions): Response
  • cookie(name: string, val: any, options: CookieOptions): Response
  • cookie(name: string, val: any): Response

download

  • download(path: string): void
  • download(path: string, filename: string): void
  • download(path: string, fn: Errback): void
  • download(path: string, filename: string, fn: Errback): void

emit

  • emit(event: string, ...args: any[]): boolean

end

  • end(): void
  • end(buffer: Buffer, cb?: Function): void
  • end(str: string, cb?: Function): void
  • end(str: string, encoding?: string, cb?: Function): void
  • end(data?: any, encoding?: string): void

format

  • format(obj: any): Response
  • 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>');
     },
    
     'appliation/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 Response

get

  • get(field: string): string

getHeader

  • getHeader(name: string): string

header

  • header(field: any): Response
  • header(field: string, value?: string): Response

links

  • links(links: any): Response

listeners

  • listeners(event: string): Function[]

location

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

    The given url can also be the name of a mapped url, for example by default express supports "back" which redirects to the Referrer or Referer headers or "/".

    Examples:

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

    Mounting:

    When an application is mounted and res.location() is given a path that does not lead with "/" it becomes relative to the mount-point. For example if the application is mounted at "/blog", the following would become "/blog/login".

     res.location('login');
    

    While the leading slash would result in a location of "/login":

     res.location('/login');
    

    Parameters

    • url: string

    Returns Response

on

  • on(event: string, listener: Function): EventEmitter

once

  • once(event: string, listener: Function): EventEmitter

redirect

  • redirect(url: string): void
  • redirect(status: number, url: string): void
  • redirect(url: string, status: number): void

removeAllListeners

  • removeAllListeners(event?: string): EventEmitter

removeHeader

  • removeHeader(name: string): void

removeListener

  • removeListener(event: string, listener: Function): EventEmitter

render

  • render(view: string, options?: Object, callback?: function): void
  • render(view: string, callback?: function): 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
    • Optional options: Object
    • Optional callback: function
        • (err: Error, html: string): void
        • Parameters

          • err: Error
          • html: string

          Returns void

    Returns void

  • Parameters

    • view: string
    • Optional callback: function
        • (err: Error, html: string): void
        • Parameters

          • err: Error
          • html: string

          Returns void

    Returns void

sendFile

  • sendFile(path: string): void
  • sendFile(path: string, options: any): void
  • sendFile(path: string, fn: Errback): void
  • sendFile(path: string, options: any, fn: Errback): void
  • Transfer the file at the given path.

    Automatically sets the Content-Type response header field. The callback fn(err) is invoked when the transfer is complete or when an error occurs. Be sure to check res.sentHeader if you wish to attempt responding, as the header and some data may have already been transferred.

    Options:

    • maxAge defaulting to 0 (can be string converted by ms)
    • root root directory for relative filenames
    • headers object of headers to serve with file
    • dotfiles serve dotfiles, defaulting to false; can be "allow" to send them

    Other options are passed along to send.

    Examples:

    The following example illustrates how res.sendFile() may be used as an alternative for the static() middleware for dynamic situations. The code backing res.sendFile() is actually the same code, so HTTP cache support etc is identical.

    app.get('/user/:uid/photos/:file', function(req, res){
      var uid = req.params.uid
        , file = req.params.file;
    
      req.user.mayViewFilesFrom(uid, function(yes){
        if (yes) {
          res.sendFile('/uploads/' + uid + '/' + file);
        } else {
          res.send(403, 'Sorry! you cant see that.');
        }
      });
    });
    
    api

    public

    Parameters

    • path: string

    Returns void

  • Parameters

    • path: string
    • options: any

    Returns void

  • Parameters

    • path: string
    • fn: Errback

    Returns void

  • Parameters

    • path: string
    • options: any
    • fn: Errback

    Returns void

sendStatus

  • sendStatus(code: number): Response
  • Set the response HTTP status code to statusCode and send its string representation as the response body.

    link

    http://expressjs.com/4x/api.html#res.sendStatus

    Examples:

    res.sendStatus(200); // equivalent to res.status(200).send('OK') res.sendStatus(403); // equivalent to res.status(403).send('Forbidden') res.sendStatus(404); // equivalent to res.status(404).send('Not Found') res.sendStatus(500); // equivalent to res.status(500).send('Internal Server Error')

    Parameters

    • code: number

    Returns Response

sendfile

  • sendfile(path: string): void
  • sendfile(path: string, options: any): void
  • sendfile(path: string, fn: Errback): void
  • sendfile(path: string, options: any, fn: Errback): void

set

  • set(field: any): Response
  • set(field: string, value?: string): Response

setHeader

  • setHeader(name: string, value: string): void

setMaxListeners

  • setMaxListeners(n: number): void

status

  • status(code: number): Response

type

  • type(type: string): Response
  • Set Content-Type response header with type through mime.lookup() when it does not contain "/", or set the Content-Type to type otherwise.

    Examples:

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

    Parameters

    • type: string

    Returns Response

write

  • write(buffer: Buffer): boolean
  • write(buffer: Buffer, cb?: Function): boolean
  • write(str: string, cb?: Function): boolean
  • write(str: string, encoding?: string, cb?: Function): boolean
  • write(str: string, encoding?: string, fd?: string): boolean
  • write(chunk: any, encoding?: string): any

writeContinue

  • writeContinue(): void

writeHead

  • writeHead(statusCode: number, reasonPhrase?: string, headers?: any): void
  • writeHead(statusCode: number, headers?: any): void

Static listenerCount

  • listenerCount(emitter: EventEmitter, event: string): number

Generated using TypeDoc