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 ID to 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 Error output and the system log.

  • Adjustable timeout: prevents long waits from stalling your flow by tuning the Timeout (s) control.

πŸ“ Usage Instructions

  1. Provide a boolean signal to Enable Condition when you want the request to run.

  2. Enter the endpoint URL into Server Address.

  3. If the endpoint returns JSON and you only need a single value, set Response Data ID to the JSON key you want (leave empty to receive the whole response).

  4. Adjust Timeout (s) if the server is slow or if you want quicker failure handling.

  5. Read results from the Status Code, Error, and Response outputs 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 Edge block 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 - Post block.

  • Use Parse Data Dictionary or Data to JSON to extract and format structured data from the Response output before saving or forwarding.

  • To log or save repeated API responses, connect outputs to CSV Export or SQL-DB Operations for persistent storage.

  • Use Debug Input to 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 Address and verify network access to the server. Increase Timeout (s) for slow servers.

  • Problem: Error output contains an HTTP status or message.

    • Inspect Status Code to 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 like Parse Data Dictionary to 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?