2x

Chat API Playground

https://github.com/Athlon1600/chat

If this is your first time viewing this page, the chat on the left will not work until you join some room and login as either a registered user or a guest user.

Sections below will show how to do all of those, and show exact request/response that go with each API call. For even more details, just look at the source code of this page or inspect the Network console on your browser.

This frontend part of the application is completely serverless, and can be deployed to run at scale at any of the many FREE CDN providers out there.

The actual backend server where all the real expensive computing is happening is located at:


Registration (optional)

Most API calls (such as ones involving posting messages, creating rooms, etc) requires you to authenticate using authentication token which is associated with your user account.

So the first step is to create your own user account:

POST /users/register [username=???, password=???]
Register





            

Login

Once your account was created successfully, you can then use those credentials to login and retrieve your personal authentication token which is required in most other API calls.

Or you may choose to skip registration step entirely, and login as a guest instantly which works by automatically creating a user from your IP address

POST /users/login [username=???, password=???, guest=???]
Login



 


            

Once you have your token, you can then login to the chat immediately from any page on your site (as long as it's hosted on the same domain) using Storage API:

window.localStorage.setItem('chat_token') = ???


Rooms

All conversations take place in rooms. You can create a new room easily, but you must be authenticated with the API first.

When you create a room, you then become the owner of that room which grants you special privileges like deleting messages and banning people.

Example request:

Authorization: Bearer <token>
POST /rooms [name=???]
New Room





            

All rooms are uniquely identified by their uid.

When embedding chat application on your site, the embed.html file accepts ?room= parameter which tells it to join that room automatically.

Example: /embed.html?room=XPeDGLvd6D
/embed.html?room={room.uid}


Messaging

Chat messages are typically sent/received via Websocket protocol, but it is possible to do the same using our HTTP REST API too:

POST /messages [message="hello from HTTP!"]

You may also delete messages:

DELETE /messages/{message.id}