File tree 6 files changed +113
-0
lines changed
6 files changed +113
-0
lines changed Original file line number Diff line number Diff line change @@ -96,6 +96,21 @@ Publish a Firebase cloud message
96
96
97
97
[ Example file v8fcm.js] ( /samples/fcm/v8fcm.js )
98
98
99
+ ## HTTP API <a name =" http_api " ></a >
100
+ * http.request()
101
+
102
+ ** http.request(options)**
103
+ Execute a http request
104
+ * ` options ` http request options as JSON string, ` String `
105
+
106
+
107
+ [ Example file v8http_httpbin_get.js] ( /samples/http/v8http_httpbin_get.js )
108
+ [ Example file v8http_httpbin_post.js] ( /samples/http/v8http_httpbin_post.js )
109
+ [ Example file v8http_httpbin_basicauth.js] ( /samples/http/v8http_httpbin_basicauth.js )
110
+ [ Example file v8http_httpbin_bearerauth.js] ( /samples/http/v8http_httpbin_bearerauth.js )
111
+ [ Example file v8http_httpbin_headers.js] ( /samples/http/v8http_httpbin_headers.js )
112
+
113
+
99
114
## Examples <a name =" examples " ></a >
100
115
## Input form example <a name =" example_input " ></a >
101
116
![ Alt text] ( /screenshots/v8input.gif?raw=true " Input form ")
Original file line number Diff line number Diff line change
1
+ //http basic auth example
2
+ function main ( ) {
3
+ rq = {
4
+ url : "http://httpbin.org/basic-auth/myuser/mypasswd" ,
5
+ method : "GET" ,
6
+ basicAuth : {
7
+ username : "myuser" ,
8
+ password : "mypasswd"
9
+ }
10
+ }
11
+
12
+ x = http . request ( JSON . stringify ( rq ) )
13
+ console . log ( x . statuscode )
14
+ console . log ( x . content )
15
+
16
+ rq . basicAuth . password = "wrong password" ;
17
+ x = http . request ( JSON . stringify ( rq ) )
18
+ console . error ( x . statuscode )
19
+
20
+ return ""
21
+ } ;
22
+
Original file line number Diff line number Diff line change
1
+ //http bearer authorization example
2
+ function main ( ) {
3
+ rq = {
4
+ url : "http://httpbin.org/bearer" ,
5
+ method : "GET" ,
6
+ authorization : "Bearer Bearertokenxyz"
7
+ }
8
+
9
+ x = http . request ( JSON . stringify ( rq ) )
10
+
11
+ console . log ( x . statuscode )
12
+ console . log ( x . content )
13
+
14
+ return ""
15
+ }
16
+
Original file line number Diff line number Diff line change
1
+ //http get example with parameters
2
+ function main ( ) {
3
+ rq = {
4
+ url : "http://httpbin.org/anything" ,
5
+ method : "GET" ,
6
+ queryParams : [
7
+ { "key" : "hello" ,
8
+ "value" : "world"
9
+ } , {
10
+ "key" : "hello1" ,
11
+ "value" : "world2"
12
+ } ]
13
+ }
14
+
15
+ x = http . request ( JSON . stringify ( rq ) )
16
+ console . log ( x . statuscode )
17
+ console . log ( x . content )
18
+
19
+ return JSON . parse ( x . content ) . url
20
+ } ;
21
+
22
+
23
+
Original file line number Diff line number Diff line change
1
+ //http header example
2
+ function main ( ) {
3
+ rq = {
4
+ url : "https://httpbin.org/headers" ,
5
+ method : "GET" ,
6
+ headerData : [
7
+ { key : "X-Timezone-Iana" , value : "Europe/Berlin" }
8
+ ]
9
+ }
10
+
11
+ x = http . request ( JSON . stringify ( rq ) )
12
+ console . log ( x . statuscode )
13
+ console . log ( x . content )
14
+
15
+ return x . statuscode
16
+ } ;
17
+
18
+
19
+
Original file line number Diff line number Diff line change
1
+ //http post example with body
2
+ function main ( ) {
3
+ rq = {
4
+ url : "https://httpbin.org/anything" ,
5
+ contentType : "application/json; charset=UTF-8" ,
6
+ method : "POST" ,
7
+ rawData : "{\"id\":42, \"myval\":\"Hello world\"}"
8
+ }
9
+
10
+ x = http . request ( JSON . stringify ( rq ) )
11
+ console . log ( x . statuscode )
12
+ console . log ( x . content )
13
+
14
+ return JSON . parse ( x . content ) . data
15
+ } ;
16
+
17
+
18
+
You can’t perform that action at this time.
0 commit comments