2021-04-01 17:34:44 -07:00
---
id: http-api
title: HTTP API
sidebar_label: HTTP API
2022-11-04 14:09:56 -07:00
sidebar_position: 2
2021-04-01 17:34:44 -07:00
---
:::info
2022-10-05 20:52:39 -07:00
This is a mini-spec on a HTTP API which can be used by browser based clients to interact with Meshtastic devices.
2021-04-01 17:34:44 -07:00
:::
## Why protobufs
- No need for JSON parsing on the resource constrained embedded server.
- Small.
2022-01-02 22:53:45 -08:00
- Already in use for all other transports (so shared testing/tooling coverage).
- Backwards and forward compatible.
2021-04-01 17:34:44 -07:00
## Request headers
2022-10-05 20:52:39 -07:00
- `Content-Type: application/x-protobuf`
- Indicates protobuf content (Meshtatic protobufs)
2021-04-01 17:34:44 -07:00
## Response headers
2022-10-05 20:52:39 -07:00
- `Content-Type: application/x-protobuf`
- Indicates protobuf content (Meshtatic protobufs)
- `X-Protobuf-Schema: <URI to the .proto schema file>`
- Not required but recommended for documentation/reflection purposes
2021-04-01 17:34:44 -07:00
## Endpoints
Two endpoints are specified:
2022-10-05 20:52:39 -07:00
### /api/v1/toradio
2021-04-01 17:34:44 -07:00
2022-10-05 20:52:39 -07:00
Allows `PUT` and `OPTION` requests.
2023-01-19 05:01:57 -08:00
#### PUT
2022-10-05 20:52:39 -07:00
2023-01-19 05:01:57 -08:00
A `PUT` request to this endpoint will be expected to contain a series of ToRadio protobuf payloads.
2021-04-01 17:34:44 -07:00
The protobufs will be sent in binary as the body for the request.
2023-08-26 15:31:48 -07:00
Only one ToRadio message per request is supported.
2022-10-05 20:52:39 -07:00
2023-01-19 05:01:57 -08:00
#### OPTIONS
2021-04-01 17:34:44 -07:00
2022-10-05 20:52:39 -07:00
An `OPTIONS`request to this endpoint will return a response status code `204` and headers only.
2021-04-01 17:34:44 -07:00
2022-10-05 20:52:39 -07:00
### /api/v1/fromradio
2021-04-01 17:34:44 -07:00
2022-10-05 20:52:39 -07:00
Allows `GET` requests.
2023-01-19 05:01:57 -08:00
#### GET
2022-10-05 20:52:39 -07:00
A `GET` request from this endpoint will return a series of FromRadio protobufs.
2021-04-01 17:34:44 -07:00
The protobufs will be sent in binary as the body for the request.
2022-10-05 20:52:39 -07:00
**Parameters**
##### **/api/v1/fromradio?all**
2023-01-19 05:01:57 -08:00
2022-10-05 20:52:39 -07:00
- `all=false` (unset default)
2023-01-19 05:01:57 -08:00
- Only one protobuf is returned.
- `all=true`
2022-10-05 20:52:39 -07:00
- All available protobufs are returned.
##### **/api/v1/fromradio?chunked**
2023-01-19 05:01:57 -08:00
2022-10-05 20:52:39 -07:00
- `chunked=false` (unset default, not yet implemented)
- The request returns all protobufs that can be delivered for the client's session (this would allow the client to poll by doing a series of requests). This is the only option that is supported in the initial release.
- `chunked=true` (not yet implemented)
- If chunked=true, the response will be a [stream of chunks](https://en.wikipedia.org/wiki/Chunked_transfer_encoding) that the server will keep open as long as the client wants. This will allow efficient streaming of new `FromRadio` protobufs as they are generated by the radio.
2021-04-01 17:34:44 -07:00
## Authentication
2023-08-26 15:31:48 -07:00
There isn't **any** user authentication. We assume access to the HTTP server is enough to establish trust.
2021-04-01 17:34:44 -07:00
## Client
2021-12-27 11:39:42 -08:00
### JavaScript
2021-04-01 17:34:44 -07:00
2023-08-06 01:35:55 -07:00
See: https://github.com/meshtastic/meshtastic.js
2021-04-01 17:34:44 -07:00
2022-10-05 20:52:39 -07:00
A reference client written in JavaScript will provide a JavaScript API for using this transport. That client will do HTTP connections, use the generated protobuf JavaScript code and provide an API that hides all of this REST plumbing. The two key methods will be `sendToRadio(packet)` and `onFromRadio(callback)`.
2021-04-01 17:34:44 -07:00
### Protoman
2023-08-19 23:26:09 -07:00
See: https://github.com/spluxx/Protoman
2021-04-01 17:34:44 -07:00
Protoman is able to interface with the Meshtastic REST API out of the box. This is useful for manual testing of the endpoints.
## Security
2021-12-27 11:39:42 -08:00
HTTP and HTTPS are both supported on the ESP32 using self signed certificates on HTTPS.
2021-04-01 17:34:44 -07:00
## Related documents
2023-08-19 23:26:09 -07:00
- Interesting slide pack on the concept: https://www.slideshare.net/mokeefe/javaone-2009-ts5276-restful-protocol-buffers