-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample.sk
More file actions
222 lines (189 loc) · 9.08 KB
/
Copy pathexample.sk
File metadata and controls
222 lines (189 loc) · 9.08 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# Example written in v0.1.2
on script load:
start http server in port 9000 with context "/"
on script unload:
stop http server
# ===============================
# Synced web request feature. (This may cause lag spike. If you don't want to happen, please use async web request feature.)
# ===============================
command get:
trigger:
set {_request} to new http request with method "GET"
set {_request}'s target url to "https://httpbin.org/get"
set {_request}'s header "Custom" to "Test"
set {_request}'s header "Content-Type" to "application/json"
set {_request}'s header "User-Agent" to "SkriptWebAPI/0.1.0"
set {_response} to response of {_request}
set {_body} to body of {_response}
broadcast "server: %{_response}'s header value from key "server"%"
broadcast "Body: %{_body}%"
broadcast "Status code: %status code of {_response}%"
broadcast "Request method: %request method of {_response}%"
command delete:
trigger:
set {_request} to new http request with method "DELETE"
set {_request}'s target url to "https://httpbin.org/delete"
set {_request}'s header "Custom" to "Test"
set {_request}'s header "Content-Type" to "application/json"
set {_request}'s header "User-Agent" to "SkriptWebAPI/0.1.0"
set {_response} to response of {_request}
set {_body} to body of {_response}
broadcast "server: %{_response}'s header value from key "server"%"
broadcast "Body: %{_body}%"
broadcast "Status code: %status code of {_response}%"
broadcast "Request method: %request method of {_response}%"
command patch:
trigger:
set {_request} to new http request with method "PATCH"
set {_request}'s target url to "https://httpbin.org/patch"
set {_request}'s header "Custom" to "Test"
set {_request}'s header "Content-Type" to "application/json"
set {_request}'s header "User-Agent" to "SkriptWebAPI/0.1.0"
set {_request}'s body to "{""json"":""test""}"
set {_response} to response of {_request}
set {_body} to body of {_response}
broadcast "server: %{_response}'s header value from key "server"%"
broadcast "Body: %{_body}%"
broadcast "Status code: %status code of {_response}%"
broadcast "Request method: %request method of {_response}%"
command post:
trigger:
set {_request} to new http request with method "POST"
set {_request}'s target url to "https://httpbin.org/post"
set {_request}'s header "Custom" to "Test"
set {_request}'s header "Content-Type" to "application/json"
set {_request}'s header "User-Agent" to "SkriptWebAPI/0.1.0"
set {_request}'s body to "{""json"":""test""}"
set {_response} to response of {_request}
set {_body} to body of {_response}
broadcast "server: %{_response}'s header value from key "server"%"
broadcast "Body: %{_body}%"
broadcast "Status code: %status code of {_response}%"
broadcast "Request method: %request method of {_response}%"
command put:
trigger:
set {_request} to new http request with method "PUT"
set {_request}'s target url to "https://httpbin.org/put"
set {_request}'s header "Custom" to "Test"
set {_request}'s header "Content-Type" to "application/json"
set {_request}'s header "User-Agent" to "SkriptWebAPI/0.1.0"
set {_request}'s body to "{""json"":""test""}"
set {_response} to response of {_request}
set {_body} to body of {_response}
broadcast "server: %{_response}'s header value from key "server"%"
broadcast "Body: %{_body}%"
broadcast "Status code: %status code of {_response}%"
broadcast "Request method: %request method of {_response}%"
command custom-method:
trigger:
set {_request} to new http request with method "CUSTOM"
set {_request}'s target url to "https://domain"
set {_request}'s header "Custom" to "Test"
set {_request}'s header "Content-Type" to "application/json"
set {_request}'s header "User-Agent" to "SkriptWebAPI/0.1.0"
set {_request}'s body to "{""json"":""test""}"
set {_response} to response of {_request}
set {_body} to body of {_response}
broadcast "server: %{_response}'s header value from key "server"%"
broadcast "Body: %{_body}%"
broadcast "Status code: %status code of {_response}%"
broadcast "Request method: %request method of {_response}%"
# ===============================
# Async web request feature.
# ===============================
command asyncget:
trigger:
set {_request} to new http request with method "GET"
set {_request}'s target url to "https://httpbin.org/get"
set {_request}'s header "Custom" to "Test"
set {_request}'s header "Content-Type" to "application/json"
set {_request}'s header "User-Agent" to "SkriptWebAPI/0.1.0"
send async web request with {_request}
command asyncdelete:
trigger:
set {_request} to new http request with method "DELETE"
set {_request}'s target url to "https://httpbin.org/delete"
set {_request}'s header "Custom" to "Test"
set {_request}'s header "Content-Type" to "application/json"
set {_request}'s header "User-Agent" to "SkriptWebAPI/0.1.0"
send async web request with {_request}
command asyncpatch:
trigger:
set {_request} to new http request with method "PATCH"
set {_request}'s target url to "https://httpbin.org/patch"
set {_request}'s header "Custom" to "Test"
set {_request}'s header "Content-Type" to "application/json"
set {_request}'s header "User-Agent" to "SkriptWebAPI/0.1.0"
set {_request}'s body to "{""json"":""test""}"
send async web request with {_request}
command asyncpost:
trigger:
set {_request} to new http request with method "POST"
set {_request}'s target url to "https://httpbin.org/post"
set {_request}'s header "Custom" to "Test"
set {_request}'s header "Content-Type" to "application/json"
set {_request}'s header "User-Agent" to "SkriptWebAPI/0.1.0"
set {_request}'s body to "{""json"":""test""}"
send async web request with {_request}
command asyncput:
trigger:
set {_request} to new http request with method "PUT"
set {_request}'s target url to "https://httpbin.org/put"
set {_request}'s header "Custom" to "Test"
set {_request}'s header "Content-Type" to "application/json"
set {_request}'s header "User-Agent" to "SkriptWebAPI/0.1.0"
set {_request}'s body to "{""json"":""test""}"
send async web request with {_request}
on web request response:
set {_response} to event-httpresponse
set {_body} to body of {_response}
set {_method} to request method of {_response}
broadcast "server: %{_response}'s header value from key "server"%"
broadcast "1: %{_body}%"
broadcast "2: %status code of {_response}%"
broadcast "3: %request method of {_response}%"
# ===============================
# Http server feature.
# ===============================
on http request received:
set {_request} to event-httpexchange
set {_method} to http request method of {_request}
set {_body} to http request body of {_request}
set {_userAgent} to http request {_request} request header value from key "User-Agent"
set {_path} to http request context path of {_request}
set {_remoteIP} to http requester ip address of {_request}
broadcast "HTTP REQUEST!"
broadcast "METHOD: %{_method}%"
broadcast "BDOY: %{_body}%"
broadcast "UA: %{_userAgent}%"
broadcast "Context: %{_path}%"
broadcast "Remote IP: %{_remoteIP}%"
set http response {_request}'s header "Custom" to "Custom header"
set http response {_request}'s header "Invisible" to "This header should not be visible because will be deleted after set."
remove http response {_request}'s header "Invisible"
set {_returnBody} to ""
if {_method} is "DELETE":
set {_returnBody} to "{""method"":""DELETE""}"
if {_method} is "GET":
set {_returnBody} to "{""method"":""GET""}"
if {_method} is "PATCH":
set {_returnBody} to "{""method"":""PATCH""}"
if {_method} is "POST":
set {_returnBody} to "{""method"":""POST""}"
if {_method} is "PUT":
set {_returnBody} to "{""method"":""PUT""}"
broadcast "RETURN BODY: %{_returnBody}%"
if {_returnBody} is not "":
reply {_request} with body {_returnBody} and response code 200
else:
# This will reply 500 without body
reply {_request}
command testreq <string> <string>:
trigger:
set {_request} to new http request with method arg-1
set {_request}'s target url to arg-2
set {_request}'s header "Custom" to "Test"
set {_request}'s header "Content-Type" to "application/json"
set {_request}'s header "User-Agent" to "SkriptWebAPI/0.1.0"
set {_request}'s body to "{""json"":""test""}"
send async web request with {_request}