# dojot-api-handler

> This is a usefull library to support any Nodejs application that intends to communicate with dojot platform. The library component maps the Dojot endpoints and lets you add the entire Dojot public API to your application. Take a look at http://www.dojot.c

Latest version **2.0.0** (published 2019-03-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install dojot-api-handler
pnpm add dojot-api-handler
yarn add dojot-api-handler
bun add dojot-api-handler
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2019-03-27 |
| First published | 2018-10-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 21.6 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Davi Cedraz |
| Maintainers | davicedraz |
| Keywords | dojot, iot |

## Links

- npm: https://www.npmjs.com/package/dojot-api-handler
- npm.io page: https://npm.io/package/dojot-api-handler

## Dependencies (6)

- [debug](https://npm.io/package/debug.md) ^4.1.1
- [morgan](https://npm.io/package/morgan.md) ^1.9.1
- [request](https://npm.io/package/request.md) ^2.87.0
- [socket.io](https://npm.io/package/socket.io.md) ^2.2.0
- [socket.io-client](https://npm.io/package/socket.io-client.md) ^2.2.0
- [request-promise-native](https://npm.io/package/request-promise-native.md) ^1.0.5

## Recent versions

- 2.0.0 (latest) — 2019-03-27
- 1.1.0 — 2018-10-30
- 1.0.0 — 2018-10-30

## README

# dojot-api-handler

This is a usefull library to support any Nodejs application that intends to communicate with dojot platform. The library component maps the Dojot endpoints and lets you add the entire Dojot public API to your application. Take a look at http://www.dojot.com.br/ for more.

## How to setup

First of all, you should have a instance of Dojot platform running locally or has access to one. check the installation guide [here](https://dojotdocs.readthedocs.io/en/latest/installation-guide.html) if you don't have yet. 

1. Create a json config file and set, at least, the following variables:

    * platformURL (has to be the URL where the Dojot platform runs on port :8000)
    * credentials (has to be the username and password registered on platform)

    ```JSON
    {
        "platformURL": "http://localhost:8000",
        "credentials": {
            "username": "admin",
            "passwd": "admin"
        }
    }
    ```

2. Import the dojot-api-handler in main of your application.

3. Set your configurations to let the library know how to operate with your Dojot instance.

    ```Javascript
    const dojot = require('dojot-api-handler');
    const config = require('./config.json');

    const dojotRouter = dojot.routes;
    const dojotApi = dojot.api;

    const apiComponents = new dojotApi(config);
    ```

Then you can build your IoT's application with your favorite tools and third-party packages and accessing the Dojot platform [endpoints](https://dojotdocs.readthedocs.io/en/latest/components-and-apis.html#exposed-apis)

```Javascript
const dojot = require('dojot-api-handler');
const config = require('./config.json');

const dojotRouter = dojot.routes;

const dojotApi = dojot.api;
const apiComponents = new dojotApi(config);

const express = require('express');
const app = express();

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

dojotRouter(app);

const http = require('http').Server(app);

dojotApi.init()
    .then((api => {
        http.listen(3000, () => {
            console.log('Dojot application server listening on port 3000');
        });
    }));
```

Now your application is ready to receive and passes the requests to the instance of the Dojot platform it is running. Feel free to add endpoints, database and other features to your app!

---
_Source: https://npm.io/package/dojot-api-handler · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
