UNPKG

1.34 kBTypeScriptView Raw
1/// <reference types="express" />
2import { ReferenceObject, SchemaObject } from '@loopback/openapi-v3';
3import { Request } from '../types';
4/**
5 * Request body with metadata
6 */
7export type RequestBody = {
8 /**
9 * Parsed value of the request body
10 */
11 value: any | undefined;
12 /**
13 * Is coercion required? Some forms of request such as urlencoded don't
14 * have rich types such as number or boolean.
15 */
16 coercionRequired?: boolean;
17 /**
18 * Resolved media type
19 */
20 mediaType?: string;
21 /**
22 * Corresponding schema for the request body
23 */
24 schema?: SchemaObject | ReferenceObject;
25};
26/**
27 * Interface to be implemented by body parser extensions
28 */
29export interface BodyParser {
30 /**
31 * Name of the parser
32 */
33 name: string | symbol;
34 /**
35 * Indicate if the given media type is supported
36 * @param mediaType - Media type
37 */
38 supports(mediaType: string): boolean;
39 /**
40 * Parse the request body
41 * @param request - http request
42 */
43 parse(request: Request): Promise<RequestBody>;
44}
45/**
46 * Plain function for body parsing
47 */
48export type BodyParserFunction = (request: Request) => Promise<RequestBody>;
49/**
50 * Binding tag for request body parser extensions
51 */
52export declare const REQUEST_BODY_PARSER_TAG = "rest.requestBodyParser";