# webrequest get/post

## GET

```lua
return function()
    local exampleHeaders = { myHeader = 'theHeaderValue' };
    local dataExample = "hello this string gets turned into a byte array behind the scenes."
    
    -- If we were using headers and body:
    -- local response = getWebRequest("https://type.fit/api/quotes", exampleHeaders, dataExample);
    
    -- without headers or body - set them as nil
    local response = getWebRequest("https://type.fit/api/quotes", nil, nil);
    local jsonObject = json.parse(response);
    
    --this website returns a json blob of quotes and authors. here we are logging the first quote.
    log(jsonObject[1].text); 
end
```

## POST

```lua
return function()
    local headers = {};
    headers["Content-Type"] = "application/json";
    local body = '{ "Id": 78912 }';
    local responseText, responseHeaders = postWebRequest(
    'https://reqbin.com/sample/post/json',
    headers, body);
    
    -- log the response as string
    --{"success":"true"}
    log(responseText);
    local parseJson = json.parse(responseText);
    log(parseJson.success);
    local backToJson = json.serialize(parseJson);
    log(backToJson);
    
    
    -- uncomment below log all response headers
    --[[
    for k, v in pairs(responseHeaders) do
        log(k .. ': ' .. v);
    end
    ]]
end
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.streamavatars.com/lua-scripting-api/api-reference-and-tips/global-functions/webrequest-get-post.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
