Skip to content
This repository has been archived by the owner on Sep 9, 2021. It is now read-only.

Add ability to response with Http Code #13

Open
shaunburdick opened this issue Sep 27, 2017 · 0 comments
Open

Add ability to response with Http Code #13

shaunburdick opened this issue Sep 27, 2017 · 0 comments

Comments

@shaunburdick
Copy link
Contributor

Add the ability to response with an object that defines a response code

import { Controller, Get, Ctx } from 'trafficlight';

class MyController {

  @Get('/foo')
  foo(@Ctx() ctx): string {
    ctx.set('Location', '/bar');
    ctx.status = 301;
    return 'Moved to /bar';
  }

  @Get('/bar')
  bar(): boolean {
    return true;
  }
}

** becomes **

import { Controller, Get, HttpCodeResponse } from 'trafficlight';

@Controller()
class MyController {

  @Get('/foo')
  foo(): HttpCodeResponse {
    return HttpCodeResponse(301, { Location: '/bar' }, 'Moved to /bar');
  }

  @Get('/bar')
  bar(): boolean {
    return true;
  }
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant