-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
request.ts
110 lines (105 loc) · 2.28 KB
/
request.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright 2020 the Fastro author. All rights reserved. MIT license.
import { ServerRequest } from "../deps.ts";
import type { Cookie } from "./cookie.ts";
import type { Query } from "./types.ts";
/**
* Request Class. It is extended from ServerRequest. One of Deno standart module.
*/
export class Request extends ServerRequest {
/**
* Get all cookies
*
* const cookies = request.getCookies();
*/
getCookies!: {
(): string[] | undefined;
};
/**
* Get cookie by name
*
* const cookie = request.getCookie("my-cookie");
*/
getCookie!: {
(name: string): string;
};
/**
* Set cookie
*
* import { Cookie } from "../mod.ts";
* const cookie: Cookie = { name: "hello", value: "pram" };
* request.setCookie(cookie);
*/
setCookie!: {
(cookie: Cookie): Request;
};
/**
* Clear cookie by name
*
* request.clearCookie("hello")
*/
clearCookie!: {
(name: string): void;
};
/**
* Redirect to the specified url, the status code is optional (default to 302)
*
* request.redirect("/", 302)
*/
redirect!: {
(url: string, status?: number): void;
};
/**
* Sends the payload to the user, could be a plain text, a buffer, JSON, stream, or an Error object.
*
* request.send("hello");
*/
send!: {
<T>(payload: string | T, status?: number, headers?: Headers): void;
};
/**
* Get url parameters
*
*
* const params = request.getParams();
*/
getParams!: {
(): string[];
};
/**
* Get payload. Could be plain text, json, multipart, or url-encoded
*
*
* const payload = await request.getPayload();
*/
getPayload!: {
// deno-lint-ignore no-explicit-any
(): Promise<any>;
};
/**
* Get query
*
* const query = await request.getQuery()
*/
getQuery!: {
(name?: string): Query;
};
/**
* URL proxy
*
* request.proxy("https://github.com/fastrodev/fastro");
*/
proxy!: {
(url: string): void;
};
/**
* Render html template
*
* request.view("index.template.html", { title: "Hello" });
*/
view!: {
// deno-lint-ignore no-explicit-any
(template: string, options?: any): void;
};
// deno-lint-ignore no-explicit-any
[key: string]: any
}