當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript restify.Response類代碼示例

本文整理匯總了TypeScript中restify.Response的典型用法代碼示例。如果您正苦於以下問題:TypeScript Response類的具體用法?TypeScript Response怎麽用?TypeScript Response使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Response類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1:

      (request: Request, response: Response) => {
        if (request.method.toUpperCase() !== "OPTIONS") {
          response.send(new restify.MethodNotAllowedError());
          return;
        } else {
          // Send the CORS headers
          //
          response.header("Access-Control-Allow-Credentials", true);
          response.header(
            "Access-Control-Allow-Headers",
            restify.CORS.ALLOW_HEADERS.join(", ")
          );
          response.header(
            "Access-Control-Allow-Methods",
            "GET, HEAD, POST, PUT, DELETE, OPTIONS"
          );
          response.header(
            "Access-Control-Allow-Origin",
            request.headers.origin
          );
          response.header("Access-Control-Max-Age", 0);
          response.header("Content-type", "text/plain charset=UTF-8");
          response.header("Content-length", 0);

          response.send(204);
        }
      }
開發者ID:SonicRainBoom,項目名稱:lib_router,代碼行數:27,代碼來源:router.ts

示例2: getSingle

export function getSingle(req: Request, res: Response, next: Next): void {
  const id = parseInt(req.params.id);
  if (id) {
    const customer = customers.find(c => c.id === id);
    if (customer) {
      res.send(customer);
      next();
    } else {
      next(new NotFoundError());
    }
  } else {
    next(new BadRequestError('Parameter id must be a number'));
  }
}
開發者ID:,項目名稱:,代碼行數:14,代碼來源:

示例3: deleteSingle

export function deleteSingle(req: Request, res: Response, next: Next): void {
  const id = parseInt(req.params.id);
  if (id) {
    const customerIndex = customers.findIndex(c => c.id === id);
    if (customerIndex !== (-1)) {
      customers.splice(customerIndex, 1);
      res.send(NO_CONTENT);
      next();
    } else {
      next(new NotFoundError());
    }
  } else {
    next(new BadRequestError('Parameter id must be a number'));
  }
}
開發者ID:,項目名稱:,代碼行數:15,代碼來源:

示例4: post

export function post(req: Request, res: Response, next: Next): void {
  if (!req.body.id || !req.body.firstName || !req.body.lastName) {
    next(new BadRequestError('Missing mandatory member(s)'));
  } else {
    const newCustomerId = parseInt(req.body.id);
    if (!newCustomerId) {
      next(new BadRequestError('ID has to be a numeric value'));
    } else {
      const newCustomer: ICustomer = { id: newCustomerId,
        firstName: req.body.firstName, lastName: req.body.lastName };
      customers.push(newCustomer);
      res.send(CREATED, newCustomer, {Location: `${req.path()}/${req.body.id}`});
    }
  }
}
開發者ID:,項目名稱:,代碼行數:15,代碼來源:

示例5: return

        return (request: Request, response: Response, route: Route) => {
            let latency = response.header('Response-Time');

            if (typeof (latency) !== 'number') {
                latency = Date.now() - request.time();
            }

            if (!latency) {
                return;
            }

            let routeSpec: RouteSpec = route && route.spec;

            let key: string = this.metricsKeyBuilder.fromRouteSpecAndStatus(routeSpec, response.statusCode);
            this.statsD.timing(key, latency);
        };
開發者ID:daptiv,項目名稱:api-metrics-client,代碼行數:16,代碼來源:metrics-logger.ts

示例6: getAll

export function getAll(req: Request, res: Response, next: Next): void {
    res.send(customers);
    next();
}
開發者ID:,項目名稱:,代碼行數:4,代碼來源:

示例7: listProducts

 private listProducts(req: Request, res: Response): void {
     res.json(200, productService.list());
 }
開發者ID:thinktecture,項目名稱:windows-developer-nodejs-typescript,代碼行數:3,代碼來源:productController.ts

示例8: addProduct

    private addProduct(req: Request, res: Response): void {
        const product = new Product(req.body.name, req.body.price);
        productService.add(product);

        res.send(200);
    }
開發者ID:thinktecture,項目名稱:windows-developer-nodejs-typescript,代碼行數:6,代碼來源:productController.ts

示例9:

 server.get('/api/test', (req: Request, res: Response) => {
   res.setCookie('myCookie', 'test' + req.cookies.foo, { path: '/' });
 });
開發者ID:AbraaoAlves,項目名稱:DefinitelyTyped,代碼行數:3,代碼來源:restify-cookies-tests.ts

示例10:

 .then(() => res.send(200), (err) => res.send(500, err));
開發者ID:hackerstolz,項目名稱:hacks,代碼行數:1,代碼來源:hackathonController.ts


注:本文中的restify.Response類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。