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


TypeScript Application.put方法代码示例

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


在下文中一共展示了Application.put方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: constructor

  constructor() {
      this.App = new express();

      this.App.get('/user/:id', UserRoute.getUser);
      this.App.put('/user', MyServer.handleRequest(UserRoute.updateUser));

      this.App.listen(3000, () => {
        console.log('server started on port 3000');
      });
  }
开发者ID:iamchairs,项目名称:demo-authorization-decorators,代码行数:10,代码来源:main.ts

示例2: function

export default function(app: Application, apiRoot: string) {
  var id = "/:id(\\d+)";
  app.get(apiRoot, send(req => Product.findAll()));
  app.get(apiRoot + id, send(req => Product.find(+req.params.id)));
  app.post(apiRoot, send(req => {
    var data = req.body;
    delete data.id;
    return Product.create(data);
  }));
  app.put(apiRoot + id, send(req => Product.update(req.body, { where: { id: +req.params.id } }), 200));
  app.delete(apiRoot + id, send(req => Product.destroy({ where: { id: +req.params.id } }), 204));
}
开发者ID:jussik,项目名称:ssgl,代码行数:12,代码来源:product-ctrl.ts

示例3: default

/**
 * Injects API routes into the application.
 */
export default (app: Application, config: Config, database: Database) => {

    /**
     * Wrapper around route handlers to provide async/await support.
     *
     */
    const api = (fn: ApiHandler) => {
        return async (req: AppRequest, res: Response) => {
            try {
                const data = await database.transaction((tx) => fn(req, tx));
                res.send({ error: false, data });
            } catch (err) {
                console.error(err);
                res.sendStatus(500);
            }
        };
    };

    // Responds feeds, no authentication.

    app.get('/feeds/:start/:count', api(async (req, tx) => {
        const start = parseInt(req.params.start, 10);
        const count = Math.min(parseInt(req.params.count, 10), 100);
        return feedRepo.allStat(tx, start, count);
    }));

    // Responds invalid feeds, no authentication.

    app.get('/invalid/:start/:count', api(async (req, tx) => {
        const start = parseInt(req.params.start, 10);
        const count = Math.min(parseInt(req.params.count, 10), 100);
        return feedRepo.invalid(tx, start, count);
    }));

    // Responds all articles, no authentication.

    app.get('/articles/:rowid/:count', api(async (req, tx) => {
        const rowid = parseInt(req.params.rowid, 10);
        const count = Math.min(parseInt(req.params.count, 10), 100);
        return articleRepo.all(tx, rowid, count);
    }));

    // Responds unread articles, no authentication.

    app.get('/unread/:rowid/:count', api(async (req, tx) => {
        const rowid = parseInt(req.params.rowid, 10);
        const count = Math.min(parseInt(req.params.count, 10), 100);
        return articleRepo.unread(tx, rowid, count);
    }));

    // Responds unseen articles, no authentication.

    app.get('/unseen/:rowid/:count', api(async (req, tx) => {
        const rowid = parseInt(req.params.rowid, 10);
        const count = Math.min(parseInt(req.params.count, 10), 100);
        return articleRepo.unseen(tx, rowid, count);
    }));

    // Responds important articles, no authentication.

    app.get('/important/:rowid/:count', api(async (req, tx) => {
        const rowid = parseInt(req.params.rowid, 10);
        const count = Math.min(parseInt(req.params.count, 10), 100);
        return articleRepo.important(tx, rowid, count);
    }));

    // Responds feed articles, no authentication.

    app.get('/feed/:uuid/:rowid/:count', api(async (req, tx) => {
        const uuid = req.params.uuid;
        const rowid = parseInt(req.params.rowid, 10);
        const count = Math.min(parseInt(req.params.count, 10), 100);
        return articleRepo.feed(tx, uuid, rowid, count);
    }));

    // Responds search results, no authentication.

    app.get('/search/:query/:rowid/:count', api(async (req, tx) => {
        const query = req.params.query as string;
        const rowid = parseInt(req.params.rowid, 10);
        const count = Math.min(parseInt(req.params.count, 10), 100);
        const words = query.split(/ +/).map((word) => {
            return word.replace(/%|_/, '');
        });
        return articleRepo.search(tx, words, rowid, count);
    }));

    // Marks article read, requires authentication.

    app.put('/article/:uuid/read', authed, api(async (req, tx) => {
        const uuid = req.params.uuid;
        return articleRepo.markRead(tx, uuid, true);
    }));

    // Marks article unread, requires authentication.

    app.put('/article/:uuid/unread', authed, api(async (req, tx) => {
//.........这里部分代码省略.........
开发者ID:rla,项目名称:feeds,代码行数:101,代码来源:api.ts


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