-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp_client.ruff
More file actions
32 lines (27 loc) · 1002 Bytes
/
http_client.ruff
File metadata and controls
32 lines (27 loc) · 1002 Bytes
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
# HTTP Client Example - Making Requests
# Demonstrates using HTTP client functions to make requests
print("=== HTTP Client Examples ===")
print("")
# Example 1: Simple GET request
print("1. Making GET request to httpbin.org...")
let response := http_get("https://httpbin.org/get")
print("Status:", response["status"])
print("Response preview:", substring(response["body"], 0, 100))
print("")
# Example 2: POST request with JSON
print("2. Making POST request with JSON...")
let post_data := to_json({"name": "Ruff", "language": "programming"})
let post_response := http_post("https://httpbin.org/post", post_data)
print("Status:", post_response["status"])
print("Posted successfully!")
print("")
# Example 3: Error handling
print("3. Error handling example...")
try {
let bad_response := http_get("https://invalid-domain-12345.com")
print("Response:", bad_response["status"])
} except err {
print("Error (expected):", err.message)
}
print("")
print("=== HTTP Client Demo Complete ===")