The http
module provides functions for making HTTP requests.
Allowed in
- build
- deploy
- destroy
- task
- trigger_sync
Usage
Load the module:
load("github.com/ocuroot/sdk/v0/http.star", "http")
Example
# Make a GET request
response = http.get("https://example.com")
print(response.body)
# Make a POST request with data and headers
data = {"key": "value"}
headers = {"Content-Type": "application/json"}
response = http.post("https://example.com/api", data=data, headers=headers)
API Reference
Makes a GET request to the given URL.
Arguments
url
: The URL to make the request to
headers
: Optional dictionary of headers to include in the request
Returns
- Response object containing status code, headers, and body
Makes a POST request to the given URL.
Arguments
url
: The URL to make the request to
data
: Optional data to send in the request body
headers
: Optional dictionary of headers to include in the request
Returns
- Response object containing status code, headers, and body
Stubs
# make_http returns a struct with get and post methods
# that can be used to make HTTP requests
def make_http():
def get(url, headers={}):
"""
Makes a GET request to the given URL.
Args:
url: The URL to make the request to.
headers: A dictionary of headers to include in the request.
"""
pass
def post(url, data=None, headers={}):
"""
Makes a POST request to the given URL.
Args:
url: The URL to make the request to.
data: The data to send in the request.
headers: A dictionary of headers to include in the request.
"""
pass
return struct(
get = get,
post = post,
)
http = make_http()