Skip to main content

On HTTP Server Endpoint Called

This block creates a custom HTTP endpoint on your device's web server. Use it to implement REST APIs and webhooks.

HTTP Server Endpoint Block

Overview​

The HTTP Server Endpoint block defines custom URL endpoints that respond to HTTP requests, enabling REST API creation and webhook reception.

Configuration​

  • Path: URL path (e.g., /api/status, /webhook)
  • Method: HTTP method (GET, POST, PUT, DELETE)

URL Path​

Define endpoint paths:

/api/temperature
/api/device/status
/webhook/alert
/control/relay/1

Use clear, RESTful path structure.

HTTP Methods​

Support different HTTP methods:

GET​

  • Retrieve data or status
  • No request body
  • Idempotent operation
GET /api/temperature
Response: {"value": 22.5, "unit": "C"}

POST​

  • Submit data
  • Create new resources
  • Include request body
POST /api/command
Body: {"action": "start"}

PUT​

  • Update existing resource
  • Replace resource data
PUT /api/settings
Body: {"temp_setpoint": 25}

DELETE​

  • Remove resource
  • Clean up data
DELETE /api/log/123

Request Handling​

Process incoming requests:

  1. HTTP Server Endpoint triggers on request
  2. Access request parameters
  3. Parse request body (if POST/PUT)
  4. Execute application logic
  5. Generate response
  6. Return to client

Request Data​

Access request information:

  • Path Parameters: Values in URL
  • Query Parameters: Key-value pairs in URL
  • Headers: HTTP headers
  • Body: Request body content
  • Client IP: Requester address

Response Generation​

Build HTTP responses:

Status Codes​

  • 200 OK: Success
  • 201 Created: Resource created
  • 400 Bad Request: Invalid input
  • 401 Unauthorized: Authentication required
  • 404 Not Found: Endpoint not found
  • 500 Internal Error: Server error

Response Body​

Return data in various formats:

  • JSON (most common for APIs)
  • Plain text
  • HTML
  • XML
  • Binary data

JSON APIs​

Create JSON REST API:

GET /api/sensors
Response:
{
"sensors": [
{"id": 1, "type": "temperature", "value": 22.5},
{"id": 2, "type": "humidity", "value": 65}
]
}

Use Cases​

Common HTTP endpoint scenarios:

  • REST API for device control
  • Webhook receivers for third-party services
  • Integration with web applications
  • Mobile app backend
  • IoT platform callbacks
  • Status monitoring endpoints

Query Parameters​

Parse URL query parameters:

GET /api/data?start=2023-01-01&end=2023-12-31&type=temperature

Access parameters:
- start: "2023-01-01"
- end: "2023-12-31"
- type: "temperature"

Request Body​

Parse POST/PUT body:

JSON​

{
"device_id": "sensor-001",
"value": 25.5,
"timestamp": "2023-10-09T12:00:00Z"
}

Form Data​

Key-value pairs from HTML forms

Raw Data​

Binary or plain text

Webhooks​

Receive webhooks from services:

  1. Create endpoint (e.g., /webhook/alert)
  2. Configure webhook URL in third-party service
  3. Receive POST requests
  4. Parse webhook payload
  5. Take action based on data

Error Handling​

Handle endpoint errors:

  • Validate input data
  • Return appropriate status codes
  • Provide error messages
  • Log errors for debugging

Integration Examples​

Integrate with:

  • Web applications
  • Mobile apps
  • IFTTT and Zapier
  • Home Assistant
  • Node-RED
  • Custom dashboards

Documentation​

Document your API:

  • List all endpoints
  • Describe parameters
  • Show example requests/responses
  • Document error codes
  • Provide authentication details

Testing​

Test endpoints:

  • Use browser for GET requests
  • Use curl or Postman for all methods
  • Test error conditions
  • Verify authentication
  • Check response formats

Troubleshooting​

Common endpoint issues:

  • 404 Not Found: Check path spelling and configuration
  • Method Not Allowed: Verify HTTP method matches
  • Authentication Failed: Check credentials and headers
  • Invalid JSON: Validate request body format

See Also​