Skip to content

REST APIs & JSON

1 Topics 1 Posts

HTTP methods, status codes, JSON parsing on device and server side

This category can be followed from the open social web via the handle rest-apis-json@forum.grapesiot.com

  • šŸ”Œ REST + JSON in IoT projects

    api json http
    1
    0 Votes
    1 Posts
    104 Views
    A
    Devices speak MQTT. Everything else — dashboards, scripts, platform config, phone apps — speaks REST and JSON. You'll meet this layer the moment a webhook never arrives, a platform call returns 403, or firmware chokes on a field that's suddenly null. Three stories you'll live through "It works in Postman but not on the device." Postman hides memory limits. On an ESP32, parsing a 4 KB JSON payload with the wrong strategy fragments the heap or blows the stack. Stream or bound your parsing, check every field's presence and type before use, and never assume a key exists because it did yesterday. The device side has its own rules — when to reach for REST over MQTT, how to keep the memory footprint flat: → HTTP and REST from the device side "The API returns 403 and I don't know why." Almost always auth scope, an expired token, or a path that doesn't match your device ID exactly. Read the status code properly — 401 means prove who you are, 403 means you proved it and still can't, 429 means slow down — then reproduce with curl before touching firmware. The underlying principles are worth learning once, properly: → HTTP and REST architectural principles → Validation, errors and authentication "The payload shape keeps changing." Firmware v1 sends this: { "t": "v1", "temp": 27.4, "hum": 62.1 } Firmware v2 sends this: { "t": "v2", "temperature_c": 27.4, "humidity_rh": 62.1, "vbat_mv": 3910 } The dashboard breaks for half the fleet. Contracts matter: version your payloads (t or v on every message), accept missing optional fields with defaults, never crash on extra fields, and reject unknown major versions with a counted alert instead of silent garbage. Design the shape deliberately up front and this class of bug disappears: → Resource modelling and API contracts Symptom → what to learn Symptom What to learn 401/403 from a platform API Auth, tokens and scopes Payload too big or shape drifting Resource modelling and contracts Works on desktop, fails on ESP32 JSON parsing under RAM limits Start at REST API Development and work through it in order. Post the method + URL + status code + body (redact secrets), and what curl says. Tag with api or json.