api-tuner 0.6.1 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -1
- package/package.json +1 -1
- package/rules/assertions.n3 +17 -0
- package/rules/curl-body.n3 +23 -0
- package/rules/headers.n3 +18 -1
- package/rules/requests.n3 +9 -4
- package/rules/util.n3 +10 -0
package/README.md
CHANGED
|
@@ -172,7 +172,19 @@ Example:
|
|
|
172
172
|
```turtle
|
|
173
173
|
tuner:body <file:data.json>
|
|
174
174
|
```
|
|
175
|
-
3. **
|
|
175
|
+
3. **URL-Encoded Form** (`application/x-www-form-urlencoded`): Use `tuner:form` directly on the `tuner:Request` object with `( name value )` pairs. Values are percent-encoded automatically.
|
|
176
|
+
```turtle
|
|
177
|
+
<#test> tuner:request [
|
|
178
|
+
a tuner:Request ;
|
|
179
|
+
tuner:method "POST" ;
|
|
180
|
+
tuner:url <http://example.com/api> ;
|
|
181
|
+
tuner:form ( "foo" "hello world" ) ;
|
|
182
|
+
tuner:form ( "bar" "Ü" ) ;
|
|
183
|
+
] .
|
|
184
|
+
```
|
|
185
|
+
This sends `foo=hello%20world&bar=%C3%9C` as the request body.
|
|
186
|
+
|
|
187
|
+
4. **Multipart Form** (`multipart/form-data`): Use `tuner:body` with a blank node containing `tuner:form` triples. Each field is a `( name value )` pair. For file uploads, use a `file:` URI and optionally a MIME type as a third element.
|
|
176
188
|
```turtle
|
|
177
189
|
tuner:body [
|
|
178
190
|
tuner:form ( "field1" "value1" ) ;
|
|
@@ -188,6 +200,18 @@ Query parameters can be added to a request using `tuner:query`.
|
|
|
188
200
|
?req tuner:query ( "name" "value" ) .
|
|
189
201
|
```
|
|
190
202
|
|
|
203
|
+
#### Basic Authentication
|
|
204
|
+
|
|
205
|
+
Use `tuner:basicAuth` to add HTTP Basic Authentication to a request. It takes a list of `( username password )` and automatically sets the `Authorization: Basic ...` header.
|
|
206
|
+
|
|
207
|
+
```turtle
|
|
208
|
+
<#test> tuner:request [
|
|
209
|
+
a tuner:Request ;
|
|
210
|
+
tuner:url <http://example.com/api> ;
|
|
211
|
+
tuner:basicAuth ( "admin" "secret" ) ;
|
|
212
|
+
] .
|
|
213
|
+
```
|
|
214
|
+
|
|
191
215
|
#### Shell Variables
|
|
192
216
|
|
|
193
217
|
Values used in request URL, headers and query params are resolved from the shell environment.
|
package/package.json
CHANGED
package/rules/assertions.n3
CHANGED
|
@@ -114,8 +114,25 @@ prefix file: <http://www.w3.org/2000/10/swap/file#>
|
|
|
114
114
|
{
|
|
115
115
|
?res tuner:header ( ?name ?value ?builtIn ) .
|
|
116
116
|
} <= {
|
|
117
|
+
?name log:rawType log:Literal .
|
|
117
118
|
?name string:lowerCase ?nameLower .
|
|
118
119
|
|
|
120
|
+
(
|
|
121
|
+
{
|
|
122
|
+
?res log:notIncludes {
|
|
123
|
+
[] a tuner:Response ;
|
|
124
|
+
tuner:headers [
|
|
125
|
+
tuner:name ?nameLower ;
|
|
126
|
+
] .
|
|
127
|
+
} .
|
|
128
|
+
}
|
|
129
|
+
{
|
|
130
|
+
("Expected header '" ?name "' but it was not present in the response")!string:concatenation^tuner:info .
|
|
131
|
+
true log:equalTo false .
|
|
132
|
+
}
|
|
133
|
+
true
|
|
134
|
+
) log:ifThenElseIn [] .
|
|
135
|
+
|
|
119
136
|
?res log:includes {
|
|
120
137
|
[] a tuner:Response ;
|
|
121
138
|
tuner:headers [
|
package/rules/curl-body.n3
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
PREFIX string: <http://www.w3.org/2000/10/swap/string#>
|
|
1
2
|
PREFIX list: <http://www.w3.org/2000/10/swap/list#>
|
|
2
3
|
PREFIX tuner: <https://api-tuner.described.at/>
|
|
3
4
|
PREFIX string: <http://www.w3.org/2000/10/swap/string#>
|
|
@@ -66,6 +67,28 @@ prefix math: <http://www.w3.org/2000/10/swap/math#>
|
|
|
66
67
|
) string:concatenation ?curlArgs .
|
|
67
68
|
} .
|
|
68
69
|
|
|
70
|
+
{
|
|
71
|
+
?req </#formUrlencoded> ?bodyArgs
|
|
72
|
+
} <= {
|
|
73
|
+
(
|
|
74
|
+
{ ?req tuner:form [] . }
|
|
75
|
+
{
|
|
76
|
+
( ?formField { ?req tuner:form ?formField } ?formFields ) log:collectAllIn [] .
|
|
77
|
+
( ( ?formFields <#encodeFormField> )!list:map "&" ) string:join ?formData .
|
|
78
|
+
( ' -d "' ?formData '"' ) string:concatenation ?bodyArgs .
|
|
79
|
+
}
|
|
80
|
+
{ ?bodyArgs log:equalTo "" }
|
|
81
|
+
) log:ifThenElseIn [] .
|
|
82
|
+
} .
|
|
83
|
+
|
|
84
|
+
{
|
|
85
|
+
( ?name ?value ) <#encodeFormField> ?urlEncodedPair .
|
|
86
|
+
} <= {
|
|
87
|
+
( "node -e 'console.log(encodeURIComponent(\"" ?value "\"))'" )!string:concatenation log:shellTrimmed ?encoded .
|
|
88
|
+
|
|
89
|
+
( ?name "=" ?encoded ) string:concatenation ?urlEncodedPair .
|
|
90
|
+
} .
|
|
91
|
+
|
|
69
92
|
{
|
|
70
93
|
( ?name ?value ) </#field> ?formField .
|
|
71
94
|
} <= {
|
package/rules/headers.n3
CHANGED
|
@@ -1,8 +1,25 @@
|
|
|
1
|
+
PREFIX log: <http://www.w3.org/2000/10/swap/log#>
|
|
1
2
|
prefix tuner: <https://api-tuner.described.at/>
|
|
2
3
|
prefix string: <http://www.w3.org/2000/10/swap/string#>
|
|
3
4
|
|
|
5
|
+
tuner:header a tuner:HeaderRule ; tuner:headerArgsRule <#defaultHeader> .
|
|
6
|
+
|
|
4
7
|
{
|
|
5
|
-
(?fieldName ?fieldValue)
|
|
8
|
+
(?fieldName ?fieldValue) <#defaultHeader> ?curlArg .
|
|
6
9
|
} <= {
|
|
7
10
|
( ' -H "' ?fieldName ":" ?fieldValue '"' ) string:concatenation ?curlArg .
|
|
8
11
|
} .
|
|
12
|
+
|
|
13
|
+
####
|
|
14
|
+
|
|
15
|
+
tuner:basicAuth a tuner:HeaderRule ; tuner:headerArgsRule <#basicAuth> .
|
|
16
|
+
|
|
17
|
+
{
|
|
18
|
+
( ?user ?password ) <#basicAuth> ?curlArgs .
|
|
19
|
+
} <= {
|
|
20
|
+
( ?user ":" ?password ) string:concatenation ?credentials .
|
|
21
|
+
|
|
22
|
+
( "node -e 'console.log(Buffer.from(\"" ?credentials "\").toString(\"base64\"))'" )!string:concatenation log:shell ?encoded .
|
|
23
|
+
|
|
24
|
+
( "Authorization" ("Basic " (?encoded "\n$" "")!string:replace)!string:concatenation ) <#defaultHeader> ?curlArgs .
|
|
25
|
+
} .
|
package/rules/requests.n3
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
|
1
2
|
PREFIX list: <http://www.w3.org/2000/10/swap/list#>
|
|
2
3
|
prefix e: <http://eulersharp.sourceforge.net/2003/03swap/log-rules#>
|
|
3
4
|
prefix log: <http://www.w3.org/2000/10/swap/log#>
|
|
@@ -20,10 +21,14 @@ prefix earl: <http://www.w3.org/ns/earl#>
|
|
|
20
21
|
true log:becomes { ?req tuner:done true } .
|
|
21
22
|
|
|
22
23
|
(
|
|
23
|
-
{ ?req tuner:header [] . }
|
|
24
24
|
{
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
?req ?headerRule [] .
|
|
26
|
+
?headerRule a tuner:HeaderRule .
|
|
27
|
+
?headerRule tuner:headerArgsRule ?headerRuleFn .
|
|
28
|
+
}
|
|
29
|
+
{
|
|
30
|
+
( ?header { ?req ?headerRule ?header } ?headers ) log:collectAllIn [] .
|
|
31
|
+
( ?headers ?headerRuleFn )!list:map string:concatenation ?headersArgs .
|
|
27
32
|
}
|
|
28
33
|
{ ?headersArgs log:equalTo "" }
|
|
29
34
|
) log:ifThenElseIn [] .
|
|
@@ -51,7 +56,7 @@ prefix earl: <http://www.w3.org/ns/earl#>
|
|
|
51
56
|
(
|
|
52
57
|
{ ?req tuner:body ?body }
|
|
53
58
|
{ ?body </#body> ( ?bodyArgs ?requestBodyFile ) }
|
|
54
|
-
{ ?
|
|
59
|
+
{ ?req </#formUrlencoded> ?bodyArgs }
|
|
55
60
|
) log:ifThenElseIn [] .
|
|
56
61
|
|
|
57
62
|
(
|
package/rules/util.n3
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
PREFIX log: <http://www.w3.org/2000/10/swap/log#>
|
|
2
|
+
prefix string: <http://www.w3.org/2000/10/swap/string#>
|
|
3
|
+
|
|
4
|
+
{
|
|
5
|
+
?command log:shellTrimmed ?output .
|
|
6
|
+
} <= {
|
|
7
|
+
?command log:shell ?outputRaw .
|
|
8
|
+
# Remove trailing newline that is usually present in shell output
|
|
9
|
+
( ?outputRaw "\n$" "" ) string:replace ?output .
|
|
10
|
+
} .
|