Git Product home page Git Product logo

black-box-data-api's Introduction

Rockwell Black Box Data API

This application is meant to be a black-box data api to provide data at various time-delays. It is not meant to show good practice!

Installation

This application was built to use minimal dependencies. The only dependencies should be installable through NPM. I wrote the application with node version 8.9.4 and npm 5.6.0 which should be fine despite them not being the latest versions. I didn't do anything crazy with the javascript. I left out typescript to keep things simple.

To install the application, just navigate to the directory with the package.json file and run:

npm install

This should install the application. You can then run the server using:

npm run start

I also included a testing framework in case you want to do anything with that. Run the tests with:

npm run test

Database

The "database" for this application is really just a few JSON files which are never modified. This way, the server database is refreshed on every restart. Instead, the "database" service maintains live in-memory references to the JSON which is loaded and parsed on startup. All API actions work with these in-memory references to appear to function like a real database without us having to install one.

Configuration

Application configuration can be found in the config/development.json file. Currently there are two properties. app.port determines what port the application listens on, and db.maxDelay determines the maximum delay in milliseconds that the system might wait for before responding. The database system waits a random amount of time from 0 to db.maxDelay milliseconds before responding.

Websocket Communication

The websocket system is designed to mimic an RPC-like format. Open a websocket to localhost:3000 and send stringified JSON messages with the following format:

{
    "entityType": "user | project",
    "userId": 0,
    "projectId": 0
    "action": "one of the below actions",
    "data": {
        "arguments": "to the command as JSON"
    }
}

Responses: The websocket system will respond to commands in the following format:

{
    "type": "userActionResponse | projectActionResponse",
    "result": {
        "JSON response": "from the server"
    }
}

Available Actions for commands

USERS:
getAll
getById
create
update
delete

PROJECTS:
getAll
getById
getByUserId
create
update
delete

EXAMPLE COMMAND: Update user's first name to Harold. Will log "{ type: 'userActionResponse', result: { message: 'User updated successfully' } }" when complete.

var websocket = new WebSocket('ws://localhost:3000');
websocket.onmessage = (message) => { console.log(JSON.parse(message.data)); };
websocket.send(JSON.stringify({
    "entityType": "user",
    "userId": 3,
    "action": "update",
    "data": {
        "fname": "Harold"
    }
}));

black-box-data-api's People

Contributors

amagid avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.