Skip to content

Instantly share code, notes, and snippets.

View pleerock's full-sized avatar

Umed Khudoiberdiev pleerock

View GitHub Profile
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 [
@JsonController()
export class BlogController {
@Get("/blogs")
getAll() {
if (accessAllowed)
throw new ForbiddenError("Access is denied");
return [
{ id: 1, name: "Blog " + filter.keyword },
createExpressServer({
container: (cls: any) => {
return MyContainer.get(cls); // here you use your container
}
});
createExpressServer({
defaultErrorHandler: false
});
createExpressServer({
controllerDirs: [__dirname + "/controllers"], // loads all controllers from the given directories. supports glob patterns
middlewareDirs: [__dirname + "/middlewares"], // loads all middlewares from the given directories. supports glob patterns
errorHandlerDirs: [__dirname + "/error-handlers"] // loads all error handlers from the given directories. supports glob patterns
});
import {Request, Response} from "express";
import {JsonController, Get, Post, Put, Patch, Delete} from "routing-controllers";
@JsonController()
export class BlogController {
@Get("/blogs")
getAll() {
return [
{ id: 1, name: "Blog 1!" },
import {Request, Response} from "express";
import {JsonController, Get, Post, Put, Patch, Delete} from "routing-controllers";
@JsonController()
export class BlogController {
@Get("/blogs")
getAll() {
return this.createPromise([
{ id: 1, name: "Blog 1!"},
import {Request, Response} from "express";
import {Controller, Get, Post, Put, Patch, Delete} from "routing-controllers";
@Controller()
export class BlogController {
@Get("/blogs")
getAll() {
return "Hello Blogs";
}
import "./BlogController";
const app = createExpressServer();
app.listen(3001);
@pleerock
pleerock / blogs-controller-express.ts
Last active May 17, 2016 07:01
routing-controllers > article1 > express.js
app.get("/blogs", function(req, res, next) {
res.send("Hello Blogs");
next();
});