REST API Overview
TheREST_API route enables HTTP communication in both directions:
- Client Mode - Make HTTP requests to external APIs triggered by MQTT messages
- Server Mode - Expose HTTP endpoints that accept data and publish it to MQTT topics
Basic Syntax
How REST API Routes Work
A REST API route bridges the HTTP and MQTT worlds. It contains events that define what happens when data flows through—either from MQTT to HTTP (client mode) or from HTTP to MQTT (server mode).REST API Configuration
REST_API_CONFIG Parameters
Client Settings
Client Settings
Server Settings
Server Settings
Authentication
Authentication
SSL/Security
SSL/Security
Client Mode
Use client mode when your broker needs to call external APIs. An MQTT message triggers the HTTP request, and the response is published back to MQTT.Event Configuration
Trigger & Routing
Trigger & Routing
Placeholder Support
Use placeholders in endpoints and bodies to insert dynamic values from the MQTT message:Client Examples
- GET Request
- POST Request
- With Authentication
Fetch data from an external API when an MQTT message arrives:When a message like
{"city": "London", "apikey": "abc123"} arrives at weather/request, the route calls the API and publishes the weather data to weather/response.Server Mode
Use server mode when external systems need to send data to your broker via HTTP. The broker exposes an HTTP endpoint that accepts requests and publishes the data to MQTT topics.Why Use Server Mode?
Server Event Configuration
Endpoint & Method
Endpoint & Method
MQTT Routing
MQTT Routing
MQTT topic where incoming HTTP data is published.
Server Examples
- Accept Sensor Data
- Multiple Endpoints
- Webhook Receiver
- CORS for Web Apps
Expose an endpoint for devices to submit readings via HTTP:Usage: Send sensor data with a simple HTTP POST:The data is published to
sensors/from/http and available to all MQTT subscribers.Combined Client and Server
A single route can operate in both modes—accepting HTTP requests AND calling external APIs:Complete Examples
- IoT Dashboard API
- Third-Party Integration
Full API for a web dashboard to read sensor data and send commands:
Troubleshooting
Connection Timeout
Connection Timeout
- Verify BASE_ADDRESS is correct
- Check firewall allows outbound connections
- Increase REQUEST_TIMEOUT if API is slow
- Verify network connectivity
SSL/TLS Errors
SSL/TLS Errors
- Ensure USE_SSL matches the API requirements
- For self-signed certificates, set IGNORE_CERT_ERRORS (not recommended for production)
- Verify certificate chain is complete
Authentication Failed
Authentication Failed
- Verify USERNAME and PASSWORD are correct
- Check Authorization header format
- Ensure API key is valid and not expired
CORS Errors
CORS Errors
- Enable CORS on the server:
WITH ENABLE_CORS "true" - Configure specific allowed origins
- Check browser console for specific CORS error messages
No Response Published
No Response Published
- Verify DESTINATION_TOPIC is configured
- Check MQTT broker connectivity
- Monitor broker logs for errors
Best Practices
Use HTTPS in Production
Use HTTPS in Production
Always use SSL/TLS for external API connections:
Set Appropriate Timeouts
Set Appropriate Timeouts
Configure timeouts based on expected API response times:
Handle Errors Gracefully
Handle Errors Gracefully
Subscribe to response topics to monitor API call results and handle failures in your Actions.
Secure Server Endpoints
Secure Server Endpoints
When exposing HTTP server endpoints:
- Use authentication where needed
- Limit CORS origins to specific domains
- Consider rate limiting at the network level
Use Environment-Specific Base URLs
Use Environment-Specific Base URLs
Configure different base URLs for development and production environments.
Next Steps
Data Pipeline Routes
MQTT bridges and email notifications.
Route Examples
See complete route configuration examples.

