Code Monkey home page Code Monkey logo

realtime-transport-dashboards's Introduction

realtime-transport-dashboards

Build Status JavaScript Style Guide

Serverless APIs for AWS to build and display Irish public transports real time data.

This is a sample serverless application that can be used for workshops or other educational purposes.

The application allows you to create dashboards. Every dashboard can contain 0 or more widgets. A widget can display real time information about a specific Dublin Bus stop, a LUAS stop or a Irish Rail station.

An example of a dashboard in terms of data structure:

Example of dashboard

The application offers APIs to create, edit and visualize dashboards and widgets.

Getting started

Before starting make sure you have the AWS CLI installed and properly configured.

You will also need Node.js version 8+.

Now clone this repository in your local workspace and run the following command to install the necessary dependencies:

npm install

Now you can deploy the service to your local AWS account with the following command:

npm run deploy

If everything went fine you should see the URL for the deployed API endpoints.

APIs

Once you deploy the functions you will be able to access the following APIS:

To run the examples, export your API endpoint prefix as PREFIX, for instance:

PREFIX="https://<api_gate_way_id>.execute-api.eu-west-1.amazonaws.com/prod"

Make sure to replace <api_gate_way_id> with you actual deployment id.

⚡️ createDashboard

Creates a new dashboard.

Endpoint

POST `/dashboard`

Payload

{
  "name": "<string>"
}

Example

curl -XPOST -i -H "Content-Type: application/json" -d '{"name":"my-dashboard"}' "${PREFIX}/dashboard"

Example Output:

HTTP/2 200
content-type: application/json

{
  "id":"d733b0b2-f429-4bdf-82ab-c9fc3b3190d7",
  "name":"my-dashboard",
  "createdAt":"2019-09-29T09:06:17.698Z",
  "updatedAt":"2019-09-29T09:06:17.698Z",
  "widgets":[]
}

⚡️ updateDashboard

Updates an existing dashboard. It basically allows you to change a dashboard name.

Endpoint

POST `/dashboard/{dashboard_id}`

Payload

{
  "name": "<string>"
}

Example

curl -XPOST -i -H "Content-Type: application/json" -d '{"name":"new-name"}' "${PREFIX}/dashboard/d733b0b2-f429-4bdf-82ab-c9fc3b3190d7"

Example Output:

HTTP/2 200
content-type: application/json
content-length: 154

{
  "createdAt":"2019-09-29T13:14:47.299Z",
  "widgets":[],
  "id":"d733b0b2-f429-4bdf-82ab-c9fc3b3190d7",
  "name":"new-name",
  "updatedAt":"2019-09-29T13:15:37.134Z"
}

⚡️ deleteDashboard

Deletes an existing dashboard

Endpoint

DELETE `/dashboard/{dashboard_id}`

Example

curl -XDELETE -i "${PREFIX}/dashboard/d733b0b2-f429-4bdf-82ab-c9fc3b3190d7"

Example Output:

HTTP/2 200
content-type: application/json
content-length: 0


⚡️ getDashboard

Get data for a dashboard and real time information for every widget

Endpoint

GET `/dashboard/{dashboard_id}`

Example

curl -XGET -i "${PREFIX}/dashboard/d733b0b2-f429-4bdf-82ab-c9fc3b3190d7"

Example Output:

HTTP/2 200
content-type: application/json
content-length: 401

{
  "createdAt":"2019-09-28T14:12:03.196Z",
  "widgets":
  [
    {
      "config":{
        "type":"luas",
        "parameters":{
          "code":"STI",
          "direction":"Inbound"
        }
      },
      "id":"6cacba61-c862-4f1e-9ca4-e5dc8f67258e",
      "name":"Stillorgan LUAS inbound",
      "realtimeInfo":
      [
        {
          "direction":"Inbound",
          "destination":"Broombridge",
          "arrivingInMinutes":9,
          "expectedArrivalTime":"2019-09-29T11:59:39.000+01:00"
        }
      ]
    }
  ],
  "id":"d733b0b2-f429-4bdf-82ab-c9fc3b3190d7",
  "name":"new-name",
  "updatedAt":"2019-09-28T16:43:05.570Z"
}

⚡️ addWidget

Adds a new widget to an existing dashboard

Endpoint

POST `/dashboard/{dashboard_id}/widget`

Payload

{
  "name": "<string>",
  "config": {
    "type": "irishRail | dublinBus | luas",
    "parameters": {
      "code": "<string>",
      "direction": "<string> (optional - only for irishRail and luas)"
    }
  }
}

Example

Adds a widget to monitor the Luas Dominick stop Inbound:

curl -XPOST -i -H "Content-Type: application/json" -d '{"name": "Luas Dominick Inbound", "config": {"type": "luas", "parameters": {"code": "DOM", "direction": "Inbound"}}}' "${PREFIX}/dashboard/d733b0b2-f429-4bdf-82ab-c9fc3b3190d7/widget"

Example Output:

HTTP/2 200
content-type: application/json
content-length: 151

{
  "name":"Luas Dominick Inbound",
  "config":{
    "type":"luas",
    "parameters":{
      "code":"DOM",
      "direction":"Inbound"
    }
  },
  "id":"59b8a71b-d8c6-4569-9ec8-69c5ff0c7521"
}

⚡️ updateWidget

Updates an existing widget

Endpoint

POST `/dashboard/{dashboard_id}/widget/{widget_id}`

Payload

{
  "name": "<string>",
  "config": {
    "type": "irishRail | dublinBus | luas",
    "parameters": {
      "code": "<string>",
      "direction": "<string> (optional - only for irishRail and luas)"
    }
  }
}

Example

Changes the previous widget direction from Outbound to Inbound:

curl -XPOST -i -H "Content-Type: application/json" -d '{"name": "Luas Dominick Inbound", "config": {"type": "luas", "parameters": {"code": "DOM", "direction": "Outbound"}}}' "${PREFIX}/dashboard/d733b0b2-f429-4bdf-82ab-c9fc3b3190d7/widget/59b8a71b-d8c6-4569-9ec8-69c5ff0c7521"

Example Output:

HTTP/2 200
content-type: application/json
content-length: 151

{
  "createdAt":"2019-09-29T13:14:47.299Z",
  "widgets":[
    {
      "name":"Luas Dominick Inbound",
      "config":{
        "type":"luas",
        "parameters":{
          "code":"DOM",
          "direction":"Outbound"
        }
      },
      "id":"59b8a71b-d8c6-4569-9ec8-69c5ff0c7521"
    }
  ],
  "id":"d733b0b2-f429-4bdf-82ab-c9fc3b3190d7",
  "name":"new-name",
  "updatedAt":"2019-09-29T13:39:10.719Z"
}

⚡️ deleteWidget

Deletes an existing widget from a dashboard

Endpoint

DELETE `/dashboard/{dashboard_id}/widget/{widget_id}`

Example

curl -XDELETE -i "${PREFIX}/dashboard/d733b0b2-f429-4bdf-82ab-c9fc3b3190d7/widget/59b8a71b-d8c6-4569-9ec8-69c5ff0c7521"

Example Output:

HTTP/2 200
content-type: text/plain
content-length: 0


AWS Cleanup

If you want to remove all the resources created by this project from your AWS account you can simply run:

npm run cleanup

Utilities

This repository contains a number of utility scripts to get information for the supported realtime services:

  • Get all Dublin Bus stops: node utils/allBusStops.js
  • Get all Irish Rail stations: node utils/allRailStations.js
  • Get all Luas stops: node utils/allLuasStops.js

Contributing

Everyone is very welcome to contribute to this project. You can contribute just by submitting bugs or suggesting improvements by opening an issue on GitHub or PRs.

License

Licensed under MIT License. © Luciano Mammino.

realtime-transport-dashboards's People

Contributors

lmammino avatar matteomazza91 avatar paultreanor avatar

Watchers

 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.