Skip to content

Commit 98addfe

Browse files
cenkingunlugumuratcorlu
authored andcommitted
fix: Added missing definitions to request
* fix(master): added documentation to request & response, and added missing definitions to request
1 parent efa31c8 commit 98addfe

File tree

2 files changed

+185
-0
lines changed

2 files changed

+185
-0
lines changed

src/request.d.ts

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,104 @@ export class Request extends Readable {
1919
xhr: boolean;
2020
event: APIGatewayProxyEvent;
2121
accept: Accepts;
22+
/**
23+
* Check if the given `type(s)` is acceptable, returning
24+
* the best match when true, otherwise `undefined`, in which
25+
* case you should respond with 406 "Not Acceptable".
26+
*
27+
* The `type` value may be a single MIME type string
28+
* such as "application/json", an extension name
29+
* such as "json", a comma-delimited list such as "json, html, text/plain",
30+
* an argument list such as `"json", "html", "text/plain"`,
31+
* or an array `["json", "html", "text/plain"]`. When a list
32+
* or array is given, the _best_ match, if any is returned.
33+
*
34+
* Examples:
35+
*
36+
* // Accept: text/html
37+
* req.accepts('html');
38+
* // => "html"
39+
*
40+
* // Accept: text/*, application/json
41+
* req.accepts('html');
42+
* // => "html"
43+
* req.accepts('text/html');
44+
* // => "text/html"
45+
* req.accepts('json, text');
46+
* // => "json"
47+
* req.accepts('application/json');
48+
* // => "application/json"
49+
*
50+
* // Accept: text/*, application/json
51+
* req.accepts('image/png');
52+
* req.accepts('png');
53+
* // => undefined
54+
*
55+
* // Accept: text/*;q=.5, application/json
56+
* req.accepts(['html', 'json']);
57+
* req.accepts('html', 'json');
58+
* req.accepts('html, json');
59+
* // => "json"
60+
*
61+
* @param {String|Array} type(s)
62+
* @return {String|Array|Boolean}
63+
*/
64+
accepts(args: string | string[]): string | boolean | string[];
65+
/**
66+
* Check if the given `encoding`s are accepted.
67+
* @param {String|Array} ...encoding
68+
* @return {String|Array}
69+
*/
70+
acceptsLanguages(args: string | string[]): string | string[];
71+
/**
72+
* Return request header.
73+
*
74+
* The `Referrer` header field is special-cased,
75+
* both `Referrer` and `Referer` are interchangeable.
76+
*
77+
* Examples:
78+
*
79+
* req.get('Content-Type');
80+
* // => "text/plain"
81+
*
82+
* req.get('content-type');
83+
* // => "text/plain"
84+
*
85+
* req.get('Something');
86+
* // => undefined
87+
*
88+
* Aliased as `req.header()`.
89+
*
90+
* @param {String} key
91+
* @return {String}
92+
*/
93+
get(key: string): string | undefined;
94+
95+
header(name: string): string | undefined;
96+
97+
/**
98+
* Check if the incoming request contains the "Content-Type"
99+
* header field, and it contains the give mime `type`.
100+
*
101+
* Examples:
102+
*
103+
* // With Content-Type: text/html; charset=utf-8
104+
* req.is('html');
105+
* req.is('text/html');
106+
* req.is('text/*');
107+
* // => true
108+
*
109+
* // When Content-Type is application/json
110+
* req.is('json');
111+
* req.is('application/json');
112+
* req.is('application/*');
113+
* // => true
114+
*
115+
* req.is('html');
116+
* // => false
117+
*
118+
* @param {String|Array} types...
119+
* @return {String|false|null}
120+
*/
121+
is(types: string | string[]): string | boolean | null;
22122
}

src/response.d.ts

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,101 @@ import { Request } from "./request";
22
import { APIGatewayProxyCallback, APIGatewayProxyResult } from 'aws-lambda';
33

44
export class Response {
5+
/**
6+
* Response object constructor
7+
*
8+
* @param {Request} req Request object for this Response
9+
* @param {APIGatewayProxyCallback} callback AWS Lambda callback function
10+
*/
511
constructor(req: Request, callback: APIGatewayProxyCallback);
612
req: Request;
713
callback: APIGatewayProxyCallback;
814
responseObj: APIGatewayProxyResult;
15+
/**
16+
* Ends the response process.
17+
*/
918
end: () => void;
19+
/**
20+
* Get response header value for given key
21+
* @param {string} key Header key to get
22+
* @return {string}
23+
*/
1024
get: (key: string) => string;
25+
/**
26+
* Performs content-negotiation on the Accept HTTP header
27+
* on the request object, when present. It uses `req.accepts()`
28+
* to select a handler for the request, based on the acceptable
29+
* types ordered by their quality values. If the header is not
30+
* specified, the first callback is invoked. When no match is
31+
* found, the server responds with 406 “Not Acceptable”, or invokes
32+
* the `default` callback.
33+
*
34+
* The `Content-Type` response header is set when a callback is
35+
* selected. However, you may alter this within the callback using
36+
* methods such as `res.set()` or `res.type()`.
37+
*
38+
* The following example would respond with `{ "message": "hey" }`
39+
* when the `Accept` header field is set to “application/json”
40+
* or “*\/json” (however if it is “*\/*”, then the response will
41+
* be “hey”).
42+
*
43+
* res.format({
44+
* 'text/plain': function(){
45+
* res.send('hey');
46+
* },
47+
*
48+
* 'text/html': function(){
49+
* res.send('<p>hey</p>');
50+
* },
51+
*
52+
* 'appliation/json': function(){
53+
* res.send({ message: 'hey' });
54+
* }
55+
* });
56+
*
57+
* By default it passes an `Error`
58+
* with a `.status` of 406 to `next(err)`
59+
* if a match is not made. If you provide
60+
* a `.default` callback it will be invoked
61+
* instead.
62+
*
63+
* @param {Object} obj
64+
* @return {Response} for chaining
65+
*/
1166
format: (obj: Object) => Response;
67+
/**
68+
* Sends a JSON response. This method sends a response (with the correct content-type) that is the parameter converted to a JSON string using JSON.stringify().
69+
*
70+
* The parameter can be any JSON type, including object, array, string, Boolean, number, or null, and you can also use it to convert other values to JSON.
71+
*
72+
* ```js
73+
* res.json(null)
74+
* res.json({ user: 'tobi' })
75+
* res.status(500).json({ error: 'message' })
76+
* ```
77+
* @param {Object} body Any type of oject
78+
*/
1279
json: (body: Object) => void;
80+
/**
81+
* Sends the HTTP response.
82+
* @param {Object} body
83+
*/
1384
send: (body: Object) => void;
85+
/**
86+
* Set response header
87+
* @param {string} key Header key
88+
* @param {string} value Header value
89+
*/
1490
set: (key: string, value: string) => Response;
91+
/**
92+
* Set status code for response
93+
* @param {number} status Status code. Ex: 200, 201, 400, 404, 500 etc.
94+
*/
1595
status: (status: number) => Response;
96+
/**
97+
* Sets the Content-Type HTTP header
98+
*
99+
* @param {string} type Mime type will be set as Content-Type response header
100+
*/
16101
type: (type: string) => Response;
17102
}

0 commit comments

Comments
 (0)