Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Decorator] Create alias to Header => HeaderParams. Improve Header decorator to manage header response. #30

Closed
Romakita opened this issue Jan 15, 2017 · 1 comment

Comments

@Romakita
Copy link
Collaborator

No description provided.

@Romakita Romakita self-assigned this Jan 15, 2017
@Romakita Romakita added this to the TsExpressDecorators v1.4.0 milestone Jan 15, 2017
@Romakita
Copy link
Collaborator Author

To maintain a coherence with other decorators like @BodyParams, @QueryParam, etc... I proposed to create an alias @HeaderParams.

@Header will be used to set the header for the response. @Header will stay compatible with old implementation.

Example :

@Controller("/calendars")
export class CalendarCtrl {

   @Get("/:id")
   @Header( "Content-Type", "application/json")
    public get(
          @PathParam('id'), 
          @Header('authorization') token: string 
     ): ICalendar {

        return <ICalendar> {id: request.params.id, name: "test"};
    }
}

// OR

@Controller("/calendars")
export class CalendarCtrl {

   @Get("/:id")
   @Header( "Content-Type", "application/json")
    public get(
          @PathParam('id'), 
          @HeaderParam('authorization') token: string 
     ): ICalendar {

        return <ICalendar> {id: request.params.id, name: "test"};
    }
}

// OR

@Controller("/calendars")
export class CalendarCtrl {

    @Get("/:id")
    @Header({"Content-Type": "application/json", "status": 200})
    public get(): ICalendar {

        return <ICalendar> {id: request.params.id, name: "test"};
    }
// or
    @Get("/:id")
    @Header("Content-Type",  "application/json")
    @Header("status",  200)
    public get(): ICalendar {

        return <ICalendar> {id: request.params.id, name: "test"};
    }
}

@Romakita Romakita changed the title [Decorator] Create alias to Header => HeaderParam. Improve Header decorator to manage header response. [Decorator] Create alias to Header => HeaderParams. Improve Header decorator to manage header response. Jan 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant