TinyRT

TinyRT Used AI

4 devlogs
4h 57m
Created by GGORG

A tiny real-time database.

Timeline

GGORG
GGORG
1h 21m 28 days ago

And here are WebSockets! They inter-operate with all the other modes as you would expect.

It works very similarly to HTTP/SSE - you connect to ws://address/topic and start receiving all messages from the topic, and all messages you send get published to that topic. Simple! You can also add ?binary=true to the end of the ws:// url to receive binary messages instead of string messages.

GGORG
GGORG
1h 14m 28 days ago

Socket.IO is here!

You can now subscribe and publish messages via Socket.IO and inter-operate with the HTTP/SSE modes.

Client to server messages:
- subscribe, topic, mode? - subscribes the current socket to the topic. mode is optional (default is string)
modes:
- string - all messages get converted to strings
- binary - all messages get sent as binary (Buffer in JS)
- json - the server will try to parse all messages as JSON, or will send them as strings if the parsing fails

  • unsubscribe, topic - unsubscribes the current socket from the topic
  • message, topic, data - publishes the data to the topic. it can be binary (JS Buffer), string, or any other value (will get serialized to unformatted JSON)

The server can only send message message, with the first argument being the topic name, and the second one being the data in the selected type (see modes above).

Note: the devlog video contains an older version of the program, where the server only sends the data to the client (and doesn't send the topic name).

GGORG
GGORG
1h 59m 29 days ago

So I ditched OpenAPI as it wouldn't serve much purpose here.

Features implemented:
- GET /topic - returns the latest value from that topic
- POST /topic - publishes a value to a topic
- Server-sent-events (JavaScript EventSource) to /topic - subscribes to real-time updates to that topic and sends them as soon as they get published

The handler for GET /topic differentiates between a regular GET request and an SSE subscription by the Accept request header.

For now a topic can't contain slashes, but I'll implement that very soon, so that they can be used for scoping/namespaces.

Basic Axum + OpenAPI project

Update attachment