# REST API - Post

This function block allows you to send data to a specified REST API endpoint using a POST request. It is suitable for integrating your application with external services through an API.

## 📥 Inputs <a href="#inputs" id="inputs"></a>

`Enable Condition` A boolean input that controls whether the POST request is sent. If set to true, the request will be executed.

`Server Address` The URL of the server where the data should be posted.

`Data ID` A string identifier for the data being sent. This serves as a key in the JSON object.

`Data` The actual data to be sent to the server. This can be any type of data that needs to be posted.

## 📤 Outputs <a href="#outputs" id="outputs"></a>

`Status Code` This output provides the HTTP status code returned from the server, indicating the success or failure of the request.

`Error` This output returns an error message if the request failed.

`Response` This output provides the response text received from the server.

## 🕹️ Controls <a href="#controls" id="controls"></a>

`Timeout (s)` This field allows you to set a timeout duration for the request in seconds. If the server does not respond within this time, the request will fail.

## 🎨 Features <a href="#features" id="features"></a>

`Dynamic Request Configuration` The ability to specify a server address, data ID, and payload dynamically allows for flexible integration with various APIs.

`Comprehensive Feedback` Outputs include status code, potential error messages, and responses, making it easy to debug and validate the request.

## 📝 Usage Instructions <a href="#usage" id="usage"></a>

1. **Enable Condition**: Connect a boolean signal to the `Enable Condition` input to allow or disallow the request to be sent.
2. **Set Server Address**: Enter the server address in the `Server Address` input.
3. **Define Data ID**: Provide a string identifier for your data.
4. **Provide Data**: Connect or input the data you wish to post.
5. **Set Timeout**: Optionally, set the timeout duration for the request.
6. **Evaluate**: Run the block to send the data to the API, and review the outputs for status code, response, or errors.

## 📊 Evaluation <a href="#evaluation" id="evaluation"></a>

This function block evaluates the inputs to send a POST request to the configured REST API and provides outputs to allow you to handle the response effectively.

## 💡 Tips and Tricks <a href="#tips-and-tricks" id="tips-and-tricks"></a>

<details>

<summary>Check API Documentation</summary>

Make sure to check the API documentation of the server you are interfacing with. Some APIs may require specific headers or authentication tokens.

</details>

<details>

<summary>Validating Responses</summary>

If you expect a specific response structure, consider post-processing the response string to convert it into a dictionary or structured object for easier handling.

</details>

<details>

<summary>Using Mock Servers</summary>

If you are developing and testing, consider using mock servers like Postman or Mocky, where you can simulate API responses without hitting live endpoints.

</details>

## 🛠️ Troubleshooting <a href="#troubleshooting" id="troubleshooting"></a>

<details>

<summary>Connection Issues</summary>

If you encounter issues connecting to the server, ensure that the server address is correct and reachable from your network. Test the URL in a browser or tool like Postman.

</details>

<details>

<summary>Invalid Data Format</summary>

If the request fails due to invalid data format, ensure that the data you are sending matches the expected format as outlined in the API documentation.

</details>

<details>

<summary>Timeout Errors</summary>

If you receive timeout errors, consider increasing the timeout value in the timeout settings. This can be necessary for slow responding servers.

</details>
