In our previous blog post, we explored schema validation and created our Plan schema with CRUD operations. Today, we'll build upon that by implementing a REST API for our admin panel to manage these plans effectively.

Building SaaS Website #12: REST API Development
In our previous blog post, we explored schema validation and created our Plan schema with CRUD operations. Today, we'll build upon that by implementing a REST API for our admin panel to manage these plans effectively.
What We'll Build
We'll create an API that allows administrators to:
- View all subscription plans
- Get details of a specific plan
- Create new plans
- Update existing plans
- Delete plans
Let's start by setting up our API routes:
How Total.js API Routing Works
In Total.js, API routing is designed to be efficient and simple. Here's what's happening:
- We define one main endpoint (usually
/api/
)- We use
?
which gets replaced byCONF.$api
(defaults to/api/
) - All our API operations go through this single endpoint
- We use
- When making requests:
- All requests use POST method
- The body specifies which schema and operation to use
- The framework handles routing to the correct schema action
For example, to update a plan, instead of directly calling /api/plans_update/123
, the request would look like:
This approach means:
- One endpoint handles all our API operations
- Simpler routing management
- Better performance
- Easy to add new operations
These routes directly connect to those schema actions we created. The +API
(notice the +
) prefix ensures these routes are protected and only accessible to authenticated administrators.
Testing It Out
Our API will be used by the admin panel we'll build in the next blog post. For now, you can test it using your preferred API testing tool.
Benefits for our Admin Panel
This routing system gives us several advantages:
- Better performance (all routes use one endpoint)
- Built-in support for data encryption
- Automatic error handling
- Easy to maintain and extend
- Works seamlessly with our schemas
In real use, when our admin panel makes a request, it's all handled automatically by Total.js. We don't need to worry about the underlying mechanism - it just works!
What's Next?
In our next post, we'll create a beautiful admin interface that uses this API to manage subscription plans. We'll build a dashboard where administrators can easily view and modify plans without dealing with the API directly.
Stay tuned for more SaaS development insights! 🚀
Other posts from Total.js Platform
- 2025-02-03January report 2025
- 2025-01-01December report 2024
- 2024-12-22Merry Christmas and a Happy New Year 2025!
- 2024-12-10Total.js UI Builder: How to upload files?
- 2024-12-04Performance Testing: Total.js vs. Koa
- 2024-12-03Total.js UI Builder: Creating a Form
- 2024-12-02November report 2024
- 2024-11-26Total.js V5: Schemas and Actions
- 2024-11-25QueryBuilder in Action Part 1
- 2024-11-13Benchmarking Node.js Frameworks: selecting your framework for 2025!