HttpClient

Inherits from: Object

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.

Example
"Simple GET request"
| client <HttpClient> body <String> |
client := HttpClient new.
body := client get: 'http://example.com/api/status'.
body print
Example
"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
Example
"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

class new

Create a new HttpClient with a default 30-second timeout.

Example
| client <HttpClient> |
client := HttpClient new

Instance Methods

primitives

delete:

Perform an HTTP DELETE request. Returns the response body as a string, or nil on error.

Example
| result <String> |
result := HttpClient new delete: 'http://example.com/api/item/1'
get:

Perform an HTTP GET request. Returns the response body as a string, or nil on error.

Example
| body <String> |
body := HttpClient new get: 'http://example.com/'
post:body:

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.

Example
| result <String> |
result := HttpClient new post: 'http://example.com/api' body: 'hello'
post:body:contentType:

Perform an HTTP POST request with the given body and content type. Returns the response body as a string, or nil on error.

Example
| result <String> |
result := HttpClient new
    post: 'http://example.com/api'
    body: '{"key": "value"}'
    contentType: 'application/json'
put:body:

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.

Example
| result <String> |
result := HttpClient new put: 'http://example.com/api/item' body: 'data'