HttpClient
An HTTP client for making requests to web servers.
HttpClient wraps Go's net/http.Client with a default 30-second timeout. All request methods return the response body as a string, or nil on error.
"Simple GET request"
| client <HttpClient> body <String> |
client := HttpClient new.
body := client get: 'http://example.com/api/status'.
body print
"POST with JSON body"
| client <HttpClient> response <String> |
client := HttpClient new.
response := client post: 'http://example.com/api/data'
body: '{"name": "Alice"}'
contentType: 'application/json'.
response print
"PUT and DELETE"
| client <HttpClient> |
client := HttpClient new.
client put: 'http://example.com/api/items/1' body: '{"updated": true}'.
client delete: 'http://example.com/api/items/1'
Class Methods
primitives
Create a new HttpClient with a default 30-second timeout.
| client <HttpClient> |
client := HttpClient new
Instance Methods
primitives
Perform an HTTP DELETE request. Returns the response body as a string, or nil on error.
| result <String> |
result := HttpClient new delete: 'http://example.com/api/item/1'
Perform an HTTP GET request. Returns the response body as a string, or nil on error.
| body <String> |
body := HttpClient new get: 'http://example.com/'
Perform an HTTP POST request with the given body string. Uses 'application/octet-stream' as the default content type. Returns the response body as a string, or nil on error.
| result <String> |
result := HttpClient new post: 'http://example.com/api' body: 'hello'
Perform an HTTP POST request with the given body and content type. Returns the response body as a string, or nil on error.
| result <String> |
result := HttpClient new
post: 'http://example.com/api'
body: '{"key": "value"}'
contentType: 'application/json'
Perform an HTTP PUT request with the given body string. Uses 'application/octet-stream' as the content type. Returns the response body as a string, or nil on error.
| result <String> |
result := HttpClient new put: 'http://example.com/api/item' body: 'data'