REST API - Get
This function block performs a HTTP GET request to a web server and provides the result to the rest of your system. Use it to fetch JSON or plain-text data from REST endpoints and forward the response to other blocks for parsing, logging or storage.
π₯ Inputs
Enable Condition When True the block will attempt to fetch data from the given server address. Use this to control when requests are made.
Server Address Full URL of the server or API endpoint to query (e.g., https://api.example.com/data).
Response Data ID Optional key or path to extract a specific value from a JSON response. Leave empty to return the whole response.
π€ Outputs
Status Code HTTP status code returned by the server.
Error Error message when the request failed or server returned an error.
Response The body of the server response. This may be plain text or a parsed JSON value depending on the endpoint and the Response Data ID input.
πΉοΈ Controls
Timeout (s) Maximum time (in seconds) to wait for the server to respond before treating the request as failed. Default is 2 seconds.
π― Features
Non-blocking execution: requests are performed without freezing the user interface, so other blocks and controls stay responsive while waiting for the response.
Optional response extraction: provide a
Response Data IDto pick a single field from a JSON response when you only need a specific value.Error reporting: common failures (connection errors, timeouts, non-OK status codes) are surfaced through the
Erroroutput and the system log.Adjustable timeout: prevents long waits from stalling your flow by tuning the
Timeout (s)control.
π Usage Instructions
Provide a boolean signal to
Enable Conditionwhen you want the request to run.Enter the endpoint URL into
Server Address.If the endpoint returns JSON and you only need a single value, set
Response Data IDto the JSON key you want (leave empty to receive the whole response).Adjust
Timeout (s)if the server is slow or if you want quicker failure handling.Read results from the
Status Code,Error, andResponseoutputs and connect them to subsequent blocks for parsing, saving or alerting.
π Evaluation
When enabled and provided a valid server address, the block issues a GET request and updates its outputs when a response arrives or when an error occurs. If no response is available, default outputs are provided so downstream blocks can continue operating.
π‘ Tips and Tricks
To trigger a single request when a condition first becomes True, combine with the
Rising Edgeblock to convert a sustained True signal into a single trigger.If you need to POST data after inspecting a GET response, pair this block with the
REST API - Postblock.Use
Parse Data DictionaryorData to JSONto extract and format structured data from theResponseoutput before saving or forwarding.To log or save repeated API responses, connect outputs to
CSV ExportorSQL-DB Operationsfor persistent storage.Use
Debug Inputto display and inspect the raw outputs during development and troubleshooting.To forward fetched data to message brokers or IoT systems, connect the results to
MQTT Publish.
π οΈ Troubleshooting
Problem: No response or timeout.
Check the URL in
Server Addressand verify network access to the server. IncreaseTimeout (s)for slow servers.
Problem: Error output contains an HTTP status or message.
Inspect
Status Codeto determine if the server reported a client or server error (4xx/5xx). Confirm the endpoint and any required authentication with the API provider.
Problem: Response is JSON but required value not found.
Verify the correct key or path is provided in
Response Data ID. If the structure is nested, use a parsing block likeParse Data Dictionaryto navigate the JSON.
Problem: Requests run too frequently or during undesired times.
Control the request timing with
Logic Input,Rising Edge, or other flow-control blocks to ensure requests are sent only when needed.
Last updated
Was this helpful?