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

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

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

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

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

  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

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

Check API Documentation

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

Validating Responses

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.

Using Mock Servers

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

πŸ› οΈ Troubleshooting

Connection Issues

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.

Invalid Data Format

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.

Timeout Errors

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

Last updated