当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Response.send方法代码示例

本文整理汇总了TypeScript中restify.Response.send方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Response.send方法的具体用法?TypeScript Response.send怎么用?TypeScript Response.send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在restify.Response的用法示例。


在下文中一共展示了Response.send方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getAll

export function getAll(req: Request, res: Response, next: Next): void {
    res.send(customers);
    next();
}
开发者ID:,项目名称:,代码行数:4,代码来源:

示例6: 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

示例7:

 .then(() => res.send(200), (err) => res.send(500, err));
开发者ID:hackerstolz,项目名称:hacks,代码行数:1,代码来源:hackathonController.ts

示例8:

 .subscribe(_ => res.send(200), next, next);
开发者ID:delta62,项目名称:chore-api,代码行数:1,代码来源:chore-browse.ts


注:本文中的restify.Response.send方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。