deno.land / x / alosaur@v1.1.1 / examples / basic / areas / home / home.controller.ts

home.controller.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
import { Controller, ForbiddenError } from "alosaur/mod.ts";import { ActionParam, Body, Cookie, Delete, Get, Param, Post, Put, QueryParam, QueryParams, Req, Res,} from "alosaur/mod.ts";import { AlosaurRequest, AlosaurResponse } from "alosaur/mod.ts";import { delay } from "../../../_utils/test.utils.ts";
@Controller("/home")export class HomeController { @Get("/text") @ActionParam(0, QueryParam("name")) @ActionParam(1, QueryParam("test")) @ActionParam(2, Cookie("username")) text( name: string, test: string, username: string, ) { return `Hello world, ${name} ${test} ${username}`; }
@Get("/json") @ActionParam(0, Req()) @ActionParam(1, Res()) @ActionParam(2, QueryParam("name")) json( request: AlosaurRequest, response: AlosaurResponse, name: string, ) { return response.getRaw(); }
@Get("/json/") obj() { return {}; }
@Get("/error") error() { throw new ForbiddenError("error"); }
@Get("/query") @ActionParam(0, QueryParam("a")) @ActionParam(1, QueryParam("b")) @ActionParam(2, QueryParam("c")) @ActionParam(3, QueryParams()) query( a: string, b: string, c: string, all: any, ) { return { a, b, c, all }; }
@Put("/query") @ActionParam(0, QueryParam("a")) @ActionParam(1, QueryParam("b")) @ActionParam(2, QueryParam("c")) @ActionParam(3, Body()) putQuery( a: string, b: string, c: string, body: any, ) { return { a, b, c, ...body }; }
@Get("/test") gerTests() { return "test"; }
@Get("/test/:id") @ActionParam(0, Param("id")) gerParamId(id: string) { return id; }
@Get("/test/:id/:name") @ActionParam(0, Param("id")) @ActionParam(1, Param("name")) gerParamIdName(id: string, name: string) { return `${id} ${name}`; }
@Get("/test/:id/:name/detail") @ActionParam(0, Param("id")) @ActionParam(1, Param("name")) gerParamIdNameDetail(id: string, name: string) { return `${id} ${name} this is details page`; }
@Post("/post") @ActionParam(0, Body()) @ActionParam(1, QueryParam("name")) post(body: any, name: string) { return body; }
@Delete("/delete/:id") @ActionParam(0, Param("id")) async delete(id: number) { await delay(500); return id; }
@Get("/response-test") async responseTest() { return new Response("Object created", { status: 201, headers: new Headers([["x-alosaur-header", "test"]]), }); }}
alosaur

Version Info

Tagged at
a year ago