Creating an API endpoint that returns your application

Create a single API to fetch your application into the dashboard

Simple Nocode Apps: If your application is purely a simple nocode embed, you can directly embed a nocode application in an iframe and deliver your embed in a dashboard page, without an additional backend. This method also supports transferring current user's subscription data to the nocode application embed (works with Retool, Appsmith, Superblocks and Bubble). See some of our nocode guides for details. If you rather want to work with custom code, use the guide below.

Typically a single API call is needed from the SaaSBox dashboard to fetch and display your SaaS application. This can be a call that simply returns some data to display in a table or a set of UI widgets.

Go to the expressjs-api-backend repository in Github that you had originally forked. Let us take a look at the controller/service.js example code (some parts omitted for brevity):

exports.create_get_user_info = async function(req, res, next) {
	let user_info = jwtTokenData(req, res, next);
  	let user_data = {};
  	let user = await createNewUserDocReturnExisting(req, res, next, user_info);
  	if (user.error) {
        res.send(user.error)
    } else {
    	// Build user structure
    	user_data.id = user_info.id;
        user_data.is_admin = user.data().is_admin;
        user_data.email = user.data().email;
  		res.send({ user_data} );
  	}
}
  • This function decodes the JWT token received in the jwtTokenData and returns cleartext user information.

  • The createNewUserDocReturnExisting() call saves the user to firebase database if it did not exist, or synchronizes the user data to the database since last time (e.g. if the name, status or plan information has been changed).

  • The same function returns the user as a database object.

  • In later lines (lines 9-11) The user data is converted from the database type to a plain javascript object and sent back to our frontend as a result.

The user_data field may contain application specific data found in the database to be displayed in the frontend.

Let us also look at how the API endpoint is defined and receives requests in the routes/index.js file:

var express = require('express');
var router = express.Router();

let setup = require("../controllers/dbsetup");
let service = require("../controllers/service");

router.post("/create-get-user", service.create_get_user_info);

module.exports = router;

Here at line 7 we define a POST route, such that calling the server url at the /create-get-user path invokes the create_get_user_info function we examined earlier. (Full source code listed on this page)

Building more complex applications

The above example is a starting point that offers a method to return per-user data to each user dashboard page. You may increase the functionality by adding more API calls on the API server such as shown in the example, as well as invoking those calls from Javascript and HTML UI widgets on the frontend files.

Next up when the example is ready, we will share a complete micro-saas implementation using the methods described in this section.

A SaaS application may deliver a valuable service to your end users, may streamline and automate existing workflows for your clients, or bring your customer setup processes to an online environment, helping your customers realize your service value in the shortest time. In any case, for further help on realizing your idea, schedule a free schedule a free consultation session.

Reduced SaaS maintenance efforts

As shown in this example, a software service can be built with mere few hundred lines of code, while the rest of the service that is required in a SaaS is handled by SaaSBox. Using this methodology, significant savings are possible where one can:

  • Save up to 10 weeks from idea to launch,

  • Save paying 1-2 developers each month to maintain the application.

  • Save on cloud costs (roughly $300-$600).

  • Be efficient: Focus all resources on the core idea that makes the service unique.

Last updated