Your application needs to talk to your database. Traditionally this means writing API endpoints, handling queries, managing connections, validating inputs and formatting responses: a lot of code before you store or retrieve your first piece of data.
Ulabase provides data APIs over MongoDB in three styles, REST, GraphQL, and WebSocket, ready to use from the first day.
Three APIs, One Database
Ulabase gives you three ways to access your MongoDB data. You can use one or all three, whatever fits your application.
The REST API provides HTTP requests for CRUD operations and queries. The GraphQL API offers flexible queries that fetch exactly what you need in a single request. The WebSocket API pushes changes to your app as they happen, through change streams.
All three APIs access the same MongoDB database. Choose the API that fits each part of your application.
REST API: The Universal Choice
REST APIs are everywhere. Every programming language, framework, and platform can make HTTP requests.
What You Can Do
Create Documents
A POST request creates a new document:
curl -X POST https://c0ffee.ulabase.app/messages \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"text": "Hello World", "author": "Alice"}'
Read Documents
There are several ways to read documents: all of them, one by its id, or those that match a filter:
# Get all documents
curl https://c0ffee.ulabase.app/messages \
-H "Authorization: Bearer $TOKEN"
# Get specific document
curl https://c0ffee.ulabase.app/messages/123 \
-H "Authorization: Bearer $TOKEN"
# Query with filters
curl -G https://c0ffee.ulabase.app/messages \
--data-urlencode 'filter={"author": "Alice"}' \
-H "Authorization: Bearer $TOKEN"
Update Documents
A PATCH request updates part of an existing document:
curl -X PATCH https://c0ffee.ulabase.app/messages/123 \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"text": "Updated message"}'
Delete Documents
Deleting a document requires only its identifier:
curl -X DELETE https://c0ffee.ulabase.app/messages/123 \
-H "Authorization: Bearer $TOKEN"
Advanced Queries
Beyond basic CRUD, the REST API supports more query options. Sorting, pagination, and projection control which data is returned:
# Sort by date, limit results, select fields
curl -G https://c0ffee.ulabase.app/messages \
--data-urlencode 'sort={"date": -1}' \
--data-urlencode 'keys={"text": 1, "author": 1}' \
--data-urlencode 'pagesize=10' \
-H "Authorization: Bearer $TOKEN"
Aggregation pipelines compute aggregations over your data. You define a pipeline once on the collection, with a name, and call it with a GET:
# Run the aggregation named "stats"
curl https://c0ffee.ulabase.app/messages/_aggrs/stats \
-H "Authorization: Bearer $TOKEN"
Full-text search works across text fields, once the collection has a text index:
# Search across text fields
curl -G https://c0ffee.ulabase.app/messages \
--data-urlencode 'filter={"$text": {"$search": "hello"}}' \
-H "Authorization: Bearer $TOKEN"
Learn REST API
The complete documentation and a tutorial for the REST API are available at ulabase.com/docs/managing-data.
GraphQL API: Query What You Need
GraphQL lets you request exactly the data you need, so a query fetches neither too much nor too little.
What You Can Do
Query Documents
A GraphQL query specifies which fields to return:
{
messages(filter: {author: "Alice"}) {
_id
text
author
date
}
}
Nested Relationships
GraphQL fetches related data in a single query:
{
users {
_id
name
messages {
text
date
}
}
}
Filtered and Sorted
Filtering, sorting, and limiting can be combined:
{
messages(
filter: {author: "Alice"}
sort: {date: -1}
limit: 10
) {
_id
text
date
}
}
GraphQL App Definitions
Ulabase GraphQL APIs require you to define a GraphQL app with types and field mappings. The app definition describes your data schema and how it maps to MongoDB collections. Once you save it under GraphQL in the console, the endpoint is live at /graphql/<uri>, for example /graphql/chat.
From Your Frontend
You can call GraphQL from your frontend with fetch:
// Using fetch
const query = `{
messages(filter: {author: "Alice"}) {
_id
text
author
}
}`;
const response = await fetch('https://c0ffee.ulabase.app/graphql/chat', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ query })
});
const data = await response.json();
You can also use Apollo Client, URQL, or any other GraphQL client library.
Learn GraphQL API
The complete documentation and a tutorial for the GraphQL API are available at ulabase.com/docs/graphql.
WebSocket API: Real-Time Updates
Change streams push changes to your app over WebSocket as they happen. They suit live updates, notifications, chat features, and collaborative editing.
What You Can Do
Subscribe to Changes
You define a change stream on a collection under Change streams in the console, with a uri and the stages that select which events to send. The app then opens a WebSocket on it:
// Connect to the stream "all-messages" of the messages collection
const ws = new WebSocket('wss://alice:secret@c0ffee.ulabase.app/messages/_streams/all-messages');
// Receive real-time updates
ws.onmessage = (event) => {
const change = JSON.parse(event.data);
console.log('Document changed:', change.operationType, change.fullDocument);
// Update your UI immediately
updateUI(change);
};
A browser cannot set headers on a WebSocket, so the credentials go in the URL and the browser turns them into Basic Auth for the handshake. The user must be one of the service's users, with a permission that allows GET on the stream's path.
MongoDB Change Streams
Ulabase change streams use MongoDB Change Streams. You get real-time notifications of inserts, updates, replaces and deletes. Each event says its operationType and carries the document under fullDocument.
Filtered Subscriptions
Each client can receive only the changes that match a value it binds in the URL. The stream declares the field in notify_when, for example { "fullDocument::author": { "$var": "author" } }, and the client passes the value:
// Only receive changes to Alice's messages
const ws = new WebSocket(
'wss://alice:secret@c0ffee.ulabase.app/messages/_streams/by-author?author=Alice'
);
Real-Time Use Cases
Live Chat
A chat combines message creation over REST with real-time delivery over WebSocket:
// Send message via REST
await fetch('https://c0ffee.ulabase.app/messages', {
method: 'POST',
headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ text: 'Hello!', author: 'Alice' })
});
// Everyone subscribed via WebSocket receives update instantly
Collaborative Editing
Multiple users editing the same document see each other's changes in real time, without polling or manual refresh.
Live Dashboards
Data updates are pushed to all connected clients, so dashboards stay current without polling.
Notifications
Critical events trigger notifications to subscribed users as soon as they happen.
Learn WebSocket API
The complete documentation and a tutorial for the WebSocket API are available at ulabase.com/docs/change-streams.
Using Multiple APIs Together
The APIs can be combined, each one where it fits.
Example: Real-Time Todo App
A todo application shows how the APIs work together. The initial load uses REST or GraphQL to fetch the existing todos:
// Fetch todos on page load
const response = await fetch('https://c0ffee.ulabase.app/todos', {
headers: { 'Authorization': `Bearer ${token}` }
});
const todos = await response.json();
Live updates use WebSocket to keep all clients synchronized:
// Subscribe to changes
const ws = new WebSocket('wss://alice:secret@c0ffee.ulabase.app/todos/_streams/all-todos');
ws.onmessage = (event) => {
const change = JSON.parse(event.data);
// Update UI with real-time changes
};
Creating todos uses REST:
// User creates todo
await fetch('https://c0ffee.ulabase.app/todos', {
method: 'POST',
headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ text: 'New todo', done: false })
});
// WebSocket subscribers receive update automatically
Choosing Your API
Use REST when you need simple CRUD operations, request-response patterns, maximum compatibility, or direct HTTP requests. It is the default choice for standard data operations.
Use GraphQL when you have complex data requirements, need to fetch related data, want flexible queries, or need to reduce over-fetching.
Use WebSocket when you need real-time updates or live notifications, or when you are building collaborative features.
Use all three when an application has all these needs, and choose the API feature by feature.
Authentication Works Everywhere
REST and GraphQL take the same credentials: Basic Authentication or a JWT. A WebSocket carries the user's credentials in its URL, since a browser cannot set its headers.
// Same token works for REST and GraphQL
const token = 'your-jwt-token';
// REST
fetch('https://c0ffee.ulabase.app/messages', {
headers: { 'Authorization': `Bearer ${token}` }
});
// GraphQL
fetch('https://c0ffee.ulabase.app/graphql/chat', {
method: 'POST',
headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ query })
});
// WebSocket: one of the service's users, in the URL
new WebSocket('wss://alice:secret@c0ffee.ulabase.app/messages/_streams/all-messages');
Permissions Apply Consistently
Your permission rules apply to all APIs. REST queries, GraphQL queries and WebSocket subscriptions are all filtered by permissions.
You define permissions once, and they apply to every API.
Start Using the Data APIs
1. Create Your Service
Sign up at https://ulabase.com and create a free service.
2. Choose Your Tutorial
Select the tutorial that matches your preferred API style. The REST API Tutorial covers traditional HTTP APIs. The GraphQL API Tutorial explores flexible queries. The WebSocket API Tutorial demonstrates real-time features.
3. Build Your Application
Start making API calls. No backend code is required: the APIs are ready for your application.
Why This Matters
The traditional approach requires a lot of work. You write API endpoints for every operation. You handle query parsing and validation. You implement filtering, sorting, and pagination. You set up WebSocket server infrastructure. You write GraphQL resolvers for each type. You maintain all this code as requirements change.
With Ulabase this work is already done. The APIs exist for all operations. Filtering, sorting, and pagination are built in. Change streams are served by the platform. GraphQL needs an app definition and no resolvers. We maintain all of it.
Questions?
If you need help with the APIs or want to discuss your use case, write to us.
Contact us: support@ulabase.com
Build your app on Ulabase
Your backend is ready in minutes, and you spend your time on your app. The Free plan needs no credit card.