當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。