本文整理汇总了TypeScript中co-body.json函数的典型用法代码示例。如果您正苦于以下问题:TypeScript json函数的具体用法?TypeScript json怎么用?TypeScript json使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了json函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
app.use(async function (ctx: koa.Context, next: Function): Promise<void> {
var body: any;
// application/json
body = await parse.json(ctx.req);
// explicit limit
body = await parse.json(ctx.req, { limit: '10kb' });
// application/x-www-form-urlencoded
body = await parse.form(ctx.req);
// text/plain
body = await parse.text(ctx.req);
// either
body = await parse(ctx.req);
// custom type
body = await parse(ctx.req, { textTypes: ['text', 'html'] });
// This lib also supports ctx.req in Koa (or other libraries), so that you may simply use this instead of this.req.
// application/json
body = await parse.json(ctx);
// application/x-www-form-urlencoded
body = await parse.form(ctx);
// text/plain
body = await parse.text(ctx);
// either
body = await parse(ctx);
});
示例2: async
export const parseQuery = async (ctx: GraphQLServiceContext, next: () => Promise<void>) => {
const {request, req} = ctx
let query: Record<string, any>
if (request.is('multipart/form-data')) {
query = (request as any).body
} else if (request.method.toUpperCase() === 'POST') {
query = await json(req)
} else {
query = queryFromUrl(request.url)
}
ctx.graphql.query = query
await next()
}
示例3: function
value: function (accepts: string[] = ['json', 'urlencoded']): Promise<any> {
if (this.__cached_body) return this.__cached_body === true ? null : this.__cached_body;
let out = null;
switch (this.is(accepts)) {
case 'json':
out = parse.json(this);
break;
case 'urlencoded':
out = parse.form(this.req);
break;
}
return out == null ? null : out.then(e => {
this.__cached_body = e == null ? true : e;
return e;
});
}