-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
request.ts
130 lines (124 loc) · 2.68 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// 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 [Deno ServerRequest](https://doc.deno.land/https/deno.land/std@0.75.0/http/server.ts#ServerRequest).
*
*/
export class Request extends ServerRequest {
contentType!: string;
httpStatus!: number;
/**
* Set content type before send
*
* request.type("text/html").send("hello");
*/
type!: {
(contentType: string): Request;
};
/**
* Set HTTP Status
*
* request.status(404).send("not found");
*/
status!: {
(httpStatus: number): Request;
};
/**
* 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
}