forked from nulang-org/nulang
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13_http.nula
More file actions
29 lines (24 loc) · 1.25 KB
/
Copy path13_http.nula
File metadata and controls
29 lines (24 loc) · 1.25 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
// 13_http.nula - HTTP client via the Http built-in effect
// Demonstrates: Http.get, Http.post, response handling
//
// Run: nulang examples/13_http.nula
// Requires network access (uses httpbin.org for testing)
perform IO.print("HTTP client demo")
perform IO.print("---")
// HTTP GET request to httpbin.org
let get_url = "https://httpbin.org/get"
let get_response = perform Http.get(get_url)
perform IO.print("GET " + get_url)
perform IO.print("Response received (" + perform Int.to_string(perform String.length(get_response)) + " bytes)")
// HTTP GET with query parameters
let get_params = "https://httpbin.org/get?name=Nulang&version=1"
let param_response = perform Http.get(get_params)
perform IO.print("GET with params: received " + perform Int.to_string(perform String.length(param_response)) + " bytes")
// HTTP POST request with a JSON body
let post_url = "https://httpbin.org/post"
let post_body = "{\"language\": \"Nulang\", \"features\": [\"actors\", \"effects\", \"capabilities\"]}"
let post_response = perform Http.post(post_url, post_body)
perform IO.print("POST " + post_url)
perform IO.print("Response received (" + perform Int.to_string(perform String.length(post_response)) + " bytes)")
perform IO.print("---")
perform IO.print("HTTP demo complete!")