RESTHeart is a backend framework for MongoDB that instantly exposes REST, GraphQL, and WebSocket APIs on your database — with built-in authentication and authorization. No code required for standard CRUD operations.
Hosting RESTHeart involves running two services: the RESTHeart API server and a MongoDB database. RESTHeart connects to MongoDB at startup and immediately exposes your collections as HTTP endpoints. The two services communicate over Railway's private network, keeping MongoDB inaccessible from the public internet. RESTHeart handles all authentication, authorization, and API logic, so you can focus on building your application rather than managing backend infrastructure.
- REST APIs on MongoDB — expose any MongoDB collection as a fully queryable REST endpoint in seconds
- Backend for mobile and web apps — use RESTHeart as a BaaS without writing server-side code
- GraphQL on MongoDB — define a GraphQL schema and let RESTHeart resolve queries against your database
- Real-time apps — subscribe to MongoDB change streams via WebSocket
- Microservices — extend RESTHeart with custom plugins in Java, Kotlin, JavaScript, or TypeScript
This template deploys two services connected over Railway's private network:
RESTHeart — built from a custom Dockerfile that:
- Installs
bcryptto hash the admin password at container startup - Reads
RESTHEART_ADMIN_PASSWORDandMONGO_URIfrom environment variables - Builds the
RHOconfiguration override and starts the RESTHeart process
MongoDB — deployed from the official mongo:8.0 image with a persistent volume attached so data survives redeployments.
After deploy, verify RESTHeart is running:
curl https://<your-railway-domain>/ping
# → Greetings from RESTHeart!Create a collection and insert a document:
# Create a collection
curl -u admin:<your-password> -X PUT https://<your-railway-domain>/mydb/mycollection
# Insert a document
curl -u admin:<your-password> -X POST https://<your-railway-domain>/mydb/mycollection \
-H "Content-Type: application/json" \
-d '{"name": "hello", "from": "RESTHeart on Railway"}'
# Query documents
curl -u admin:<your-password> https://<your-railway-domain>/mydb/mycollectionRailway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.
By deploying RESTHeart on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.
RESTHeart is configured entirely through the RHO environment variable, which accepts semicolon-separated XPath expressions. The template sets it automatically at startup — you do not need to edit it manually.
To customize RESTHeart further (e.g. change mount points, disable features, add roles), refer to the RESTHeart configuration guide.
After deploy, you can point your own domain to RESTHeart from the Railway dashboard:
- Open the RESTHeart service → Settings → Networking → Custom Domain
- Enter your domain (e.g.
api.example.com) - Add the CNAME record Railway provides to your DNS
- Railway provisions a TLS certificate automatically
No changes to the RESTHeart configuration are needed.
If you know the current password, change it through the standard RESTHeart user management API — see User Management for the exact request.
After changing it, update RESTHEART_ADMIN_PASSWORD in the RESTHeart service settings so the two stay in sync. The env var is only consulted on a recovery (see below), but keeping it aligned avoids surprises later.
The RESTHEART_ADMIN_PASSWORD variable is read only on first startup, when the users collection is empty. If you no longer have the current password, you need to delete the admin document directly in MongoDB so RESTHeart re-creates it from the env var on the next start:
- Open the MongoDB service in your Railway project and connect to it (via the Railway dashboard's data view, the
railway connectCLI, or MongoDB Compass with the public proxy). - Drop the existing admin document:
use restheart db.users.deleteOne({ _id: "admin" })
- In the RESTHeart service, set
RESTHEART_ADMIN_PASSWORDto the new password you want. - Redeploy the RESTHeart service. On startup it will detect the missing admin and re-create it from the env var.
If your admin username is not admin, replace it with the value of RESTHEART_ADMIN_USER. Other users you've created via the API are preserved — only the single admin document is removed.
Running RESTHeart on Railway gives you full control but also full responsibility: backups, monitoring, upgrades, and scaling are yours to manage.
RESTHeart Cloud offers the same RESTHeart stack as a fully managed service — no infrastructure to maintain, SLA included, with a dashboard for user and permission management.
When you're ready to hand off operations, RESTHeart Cloud is the natural next step.