api-tuner 0.6.2 → 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 +13 -1
- package/package.json +1 -1
- package/rules/curl-body.n3 +23 -0
- package/rules/requests.n3 +1 -1
- 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" ) ;
|
package/package.json
CHANGED
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/requests.n3
CHANGED
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
|
+
} .
|