# Reactium + Actinium (APIs)

The default API experience with Reactium is facilitated by a [separate API server](https://docs.reactium.io/actinium/actinium-core), Actinium, coupled with a front-end module that makes integration with the API server easy.

{% hint style="info" %}
The Actinium API module is installed by default. To install it manually, use Reactium CLI:

```
npx reactium install @atomic-reactor/reactium-api
```

{% endhint %}

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.&#x20;

```javascript
$ 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.

{% code title="/SomeDomain/services.js" %}

```jsx
import Reactium from 'reactium-core/sdk'; 

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

{% endcode %}

{% hint style="success" %}
Start Actinium then start Reactium and you're good to go!
{% endhint %}

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](https://docs.reactium.io/reactium/reactium-guides/reactium-+-rest).

### Running the Full-Stack Locally

Start by installing both [Reactium](https://docs.reactium.io/installing-foundations/install) and [Actinium](https://docs.reactium.io/installing-foundations/install-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](https://docs.reactium.io/approach/architecture) 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***](https://docs.reactium.io/domain/basic-domain-model#reactium-boot.js) file. If you have the reactium-api module installed, Actinium is available out of the box as a global.&#x20;

{% code title="reactium-boot.js" lineNumbers="true" %}

```javascript
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,
});
```

{% endcode %}
