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


TypeScript micro.json函數代碼示例

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


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

示例1: async

  const graphqlHandler = async (req: MicroRequest, res: ServerResponse) => {
    let query;
    try {
      query =
        req.method === 'POST'
          ? req.filePayload || (await json(req))
          : url.parse(req.url, true).query;
    } catch (error) {
      // Do nothing; `query` stays `undefined`
    }

    try {
      const { graphqlResponse, responseInit } = await runHttpQuery([req, res], {
        method: req.method,
        options,
        query,
        request: convertNodeHttpToRequest(req),
      });
      setHeaders(res, responseInit.headers);
      return graphqlResponse;
    } catch (error) {
      if ('HttpQueryError' === error.name && error.headers) {
        setHeaders(res, error.headers);
      }

      if (!error.statusCode) {
        error.statusCode = 500;
      }

      throw error;
    }
  };
開發者ID:simonjoom,項目名稱:react-native-project,代碼行數:32,代碼來源:microApollo.ts

示例2: post

 post("/auth/checkToken", async (req: ServerRequest, res: ServerResponse) => {
   try {
     const body = (await json(req)) as { token: string; username: string };
     await verifyToken(body.token);
     send(res, 200, { token: body.token });
   } catch (e) {
     console.log(e);
     send(res, e.httpStatus || 500, e.message || null);
   }
 }),
開發者ID:Modwatch,項目名稱:API,代碼行數:10,代碼來源:auth.ts

示例3: async

const bodyParsingHandler: RequestHandler = async (req, res) => {
    const buf = await buffer(req);
    console.log(buf);
    // <Buffer 7b 22 70 72 69 63 65 22 3a 20 39 2e 39 39 7d>
    const txt = await text(req);
    // '{"price": 9.99}'
    const js: any = await json(req);
    // { price: 9.99 }
    console.log(js.price);
    return '';
};
開發者ID:AbraaoAlves,項目名稱:DefinitelyTyped,代碼行數:11,代碼來源:micro-tests.ts

示例4: post

 post("/loadorder", async (req: ServerRequest, res: ServerResponse) => {
   try {
     const body = (await json(req)) as Modwatch.Profile;
     const profile = {
       ...body,
       timestamp: new Date()
     };
     send(res, 201, await uploadProfile(profile, getToken(req)));
   } catch (e) {
     console.log(e);
     send(res, e.httpStatus || 500, e.message || null);
   }
 })
開發者ID:Modwatch,項目名稱:API,代碼行數:13,代碼來源:upload.ts

示例5: async

 async (req: ServerRequest, res: ServerResponse) => {
   try {
     const body = (await json(req)) as { password: string };
     await deleteProfile(
       decodeURIComponent(req.params.username),
       body.password,
       await getToken(req)
     );
     send(res, 200);
   } catch (e) {
     console.log(e);
     send(res, e.httpStatus || 500, e.message || null);
   }
 }
開發者ID:Modwatch,項目名稱:API,代碼行數:14,代碼來源:user.ts

示例6: function

  return async function (req: IncomingMessage, res: ServerResponse) {
    let query;
    if (req.method === 'POST') {
      try {
        query = await json(req);
      } catch (err) {
        query = undefined;
      }
    } else {
      query = url.parse(req.url, true).query;
    }

    try {
      const gqlResponse = await runHttpQuery([req, res], {
        method: req.method,
        options: options,
        query: query,
      });

      res.setHeader('Content-Type', 'application/json');
      return gqlResponse;
    } catch (error) {
      if ('HttpQueryError' === error.name) {
        if (error.headers) {
          Object.keys(error.headers).forEach((header) => {
            res.setHeader(header, error.headers[header]);
          });
        }
      }

      if (!error.statusCode) {
        error.statusCode = 500;
      }

      throw error;
    }
  };
開發者ID:convoyinc,項目名稱:apollo-server,代碼行數:37,代碼來源:microApollo.ts


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