Created
May 17, 2016 09:05
-
-
Save pleerock/b775439e2688c38847efac4bb9fb9d7b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {JsonController} from "routing-controllers"; | |
import {Get, Post, Put, Patch, Delete} from "routing-controllers"; | |
import {QueryParam, Param, Body} from "routing-controllers"; | |
@JsonController() | |
export class BlogController { | |
@Get("/blogs") | |
getAll(@QueryParam("keyword", { required: true }) keyword: string) { | |
return [ | |
{ id: 1, name: keyword }, | |
{ id: 2, name: keyword } | |
]; | |
} | |
@Get("/blogs/:id") | |
getOne(@Param("id") id: number, @QueryParam("name") name: string) { | |
return { id: id, name: name }; | |
} | |
@Post("/blogs") | |
post(@Body() blog: any) { | |
return "Blog " + JSON.stringify(blog) + " !saved!"; | |
} | |
@Put("/blogs/:id") | |
put(@Param("id") id: number) { | |
return "Blog #" + id + " has been putted!"; | |
} | |
@Patch("/blogs/:id") | |
patch(@Param("id") id: number) { | |
return "Blog #" + id + " has been patched!"; | |
} | |
@Delete("/blogs/:id") | |
remove(@Param("id") id: number) { | |
return "Blog #" + id + " has been removed!"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment