Random set of APIs which are designed for my own use. Written in golang.
Endpoints
/live-users-count
An API to get the number of users who are currently online. Works by using Server-Sent Events instead of
WebSockets. The d
parameter is used to specify the domain for which you want to get the live user
count. This will
subscribe the user to the domain's live user count and increase the count.
Example
// Connect to the /live-user-count for example.com
const eventSource = new EventSource(
"//rando.sahithyan.dev/live-users-count?d=example.com",
{},
);
// Whenever the user count changes, the server will send a message event
eventSource.addEventListener("message", (event) => {
console.log(event.data);
});
// "open" event is triggered when the connection is established successfully
eventSource.addEventListener("open", () => {
console.log("connected");
});
Parameters
Parameter | Type | Description |
---|---|---|
d | string | The domain for which you want to get the live user count. Will respond with an error if not provided. |
peek | boolean | When provided (set to true), the current subcriber will not be counted as a user. Default: false. |