The purpose of this service is to be your real-time BaaS (Backend as a Service).
Broker is a SSE message broker that requires you write no backend code to have a full real-time API.
Broker is born from the need that rather than building a complex REST API with web-sockets and a SQL database to provide reactive web forms (like for React) there must be a simpler way.
Broker follows an insert-only/publish/subscribe paradigm rather than a REST CRUD paradigm.
In Broker you create a user, login, then insert an event with its data. Broker then publishes the event via SSE.
When the client first subscribes to the SSE connection all the latest events and data is sent to the client. Combined with sending the latest event via SSE when subscribed negates the necessity to do any GET API requests in the lifecycle of an event.
The side-effect of this system is that the latest event is the schema. This is pure NoSQL as the backend is agnostic to the event data.
Why compete against Parse Server, Auth0, and Firebase?
Will broker work with mobile apps?
Yes with React Native. There may be native 3rd party libraries for SSE that work. In the future official libraries may be made available for native platforms.
html
POST /create_user
- public endpoint
json
{
"username": "bob",
"password": "password1",
"admin_token": "letmein",
"tenant_name": "tenant_1",
"email": "bob@hotmail.com",
"scopes": ["news:get", "news:post"],
"data": {
"name": "Robert Wieland",
"image": "https://img.com/bucket/123/123.jpg"
}
}
- admin_token is required and can be set in the command args - it is for not allowing everyone to add a user - the default is letmein
- email and data is an optional field
will return 200 or 500 or 400
html
POST /login
- public endpoint
json
{
"username": "bob",
"password": "password1"
}
will return
json
{
"jwt": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2MTc2NzQ5MTUsImlhdCI6MTYxNzU4ODUxNSwiaXNzIjoiRGlzcGF0Y2hlciIsInN1YiI6ImZvbyJ9.OwiaZJcFUC_B0CA0ffRZVTWKRf5_vQ7vt5USNJEeKRE"
}
- note: iat is the issue time, exp is the expiry time, sub is the username, iss is Broker, while aud is the user scopes joined with a comma like in this example news:get,news:post
- note: if you need to debug your JWT then visit jwt.io
html
GET /sse
- authenticated endpoint (Authorization: Bearer {jwt}) or (Authorization: Basic {username:password})
- connect your sse-client to this endpoint using broker-client
- note: broker-client uses fetch as eventsource doesn't support headers
html
POST /insert
- authenticated endpoint (Authorization: Bearer {jwt}) or (Authorization: Basic {username:password})
json
{
"event": "test",
"data": {
"name": "robert",
"image": "https://img.com/bucket/123/123.jpg"
}
}
will return: 200 or 500 or 400 or 401
html
GET /verify
- authenticated endpoint (Authorization: Bearer {jwt}) or (Authorization: Basic {username:password})
- verifies that the user is authenticated on broker - used for external services like portal
will return: 200 or 500 or 401
html
POST /revoke_user
- public endpoint
json
{
"admin_token": "letmein",
"username": "bob"
}
will return: 200 or 500 or 400 or 401
- note: revoked users cannot login
html
POST /unrevoke_user
- public endpoint
json
{
"admin_token": "letmein",
"username": "bob"
}
will return: 200 or 500 or 400 or 401
html
POST /list_users
- public endpoint
json
{
"admin_token": "letmein",
}
will return: 200 or 500 or 400 or 401
200 - will return an array of objects
json
[
{
"id": "69123c04-fa42-4193-a6c5-ab2fc27658b1",
"password": "***",
"revoked": false,
"tenant_name": "tenant_1",
"username": "bob",
"email": "bob@hotmail.com",
"scopes": ["news:get", "news:post"],
"data": {
"name": "Robert Wieland",
"image": "https://img.com/bucket/123/123.jpg"
}
}
]
- note: email and data can be null
html
POST /get_user
- public endpoint
json
{
"admin_token": "letmein",
"username": "bob"
}
will return: 200 or 500 or 400 or 401
200 - will return an array of objects
json
{
"id": "69123c04-fa42-4193-a6c5-ab2fc27658b1",
"password": "***",
"revoked": false,
"tenant_name": "tenant_1",
"username": "bob",
"email": "bob@hotmail.com",
"scopes": ["news:get", "news:post"],
"data": {
"name": "Robert Wieland",
"image": "https://img.com/bucket/123/123.jpg"
}
}
- note: email and data can be null
html
POST /update_user
- public endpoint
json
{
"admin_token": "letmein",
"username": "bob",
"tenant_name": "tenant_2",
"password": "new_password",
"email": "bober@hotmail.com",
"scopes": ["news:get", "news:post"],
"data": {
"name": "Robert Falcon",
"image": "https://img.com/bucket/123/1234.jpg"
}
}
- note: tenant_name, password, email, data are optional fields
will return: 200 or 500 or 400 or 401
html
GET or HEAD /
- public endpoint
will return: 200
cargo install broker
origin can be passed in as a flag - default *port can be passed in as a flag - default 8080 - can only be set for unsecure connectionsjwt_expiry for jwts can be passed in as a flag - default 86400jwt_secret for jwts should be passed in as a flag - default secretsecure flag for https and can be true or false - default falseauto_cert flag for an autorenewing LetsEncrypt SSL cert can be true or false - requires a resolvable domain - default true key_path flag when auto_cert is false to set the SSL key path for your own cert - default certs/private_key.pemcert_path flag when auto_cert is false to set the SSL cert path for your own cert - default certs/chain.pemcerts flag is the storage path of LetsEncrypt certs - default certsdb flag is the path where the embedded database will be saved - default dbdomain flag is the domain name (e.g. api.broker.com) of the domain you want to register with LetsEncrypt - must be fully resolvable admin_token flag is the password for the admin to add users - default letmeinpassword_checker flag enables zxcvbn password checking - default false./broker --secure="true" --admin_token"23ce4234@123$" --jwt_secret="xTJEX234$##$" --domain="api.broker.com" --password_checker="true"There is an example systemctl service for Ubuntu called broker.service in the code