本文整理汇总了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;未经允许,请勿转载。 |
请发表评论