Reactium + Actinium (APIs)

Reactium foundational web app framework comes with built-in support for the complementary API framework, Actinium, giving you rapid access to built-in cloud functions, and your own API extensions.

The default API experience with Reactium is facilitated by a separate API server, Actinium, coupled with a front-end module that makes integration with the API server easy.

The Actinium API module is installed by default. To install it manually, use Reactium CLI:

npx reactium install @atomic-reactor/reactium-api

Out of the box Reactium is ready to work with Actinium with a little configuration. Simply set the REST_API_URL and the ACTINIUM_APP_ID environment variables.

$ export REST_API_URL=https://my.actinium.url/api
$ export ACTINIUM_APP_ID=Actinium
$ npm start

In your Reactium code use the default helper module provided to immediately begin using the Actinium SDK.

/SomeDomain/services.js
import Reactium from 'reactium-core/sdk'; 

export default {
    myCloudFunction: params => Reactium.Cloud.run('myCloudFunction', params)
    .then(data => { /* do something */ })
};

Start Actinium then start Reactium and you're good to go!

While the extensible Reactium SDK is our opinion for the best way to quickly add backend API functionality to your webapp, supporting other client-side APIs is a snap. See Reactium + REST.

Running the Full-Stack Locally

Start by installing both Reactium and Actinium locally.

Once you have Reactium and Actinium installed, you can run the UI server and the API server on the same machine.

For local development, Actinium runs on localhost on port 9000 and Reactium will run on localhost on port 3000 for browser-sync (and 3030 for the base Node/Express server).

See the Architechure Diagram to get a visual sense of the relationship between these two servers. In summary, Reactium is a micro-service for serving the front-end of your web-app, and Actinium is a micro-service for building an API (and database) for your application.

Using Actinium in Express Middleware

There may be a time when you will want access to Actinium when creating Express middleware inside of a reactium-boot.js file. If you have the reactium-api module installed, Actinium is available out of the box as a global.

reactium-boot.js
const bodyParser = require('body-parser');
const express = require('express');
const router = express.Router();

router.use(bodyParser.json());
router.use(bodyParser.urlencoded({ extended: false }));

router.post('/auth', async (req, res) => {
    const { username, password } = req.body;
    const result = await Actinium.Cloud.run('my-auth-function', { username, password });
    res.json(result);
});

ReactiumBoot.Server.Middleware.register('auth', {
    name: 'auth',
    use: router,
    order: ReactiumBoot.Enums.priority.highest,
});

Last updated