A lightweight router for the Power BI JavaScript SDK which allows a hosting application to register routes to extend and integrate with Power BI embedded components.
Перейти к файлу
Matt Mazzola 39d50f59fb Auto-format all files to use consistent tab size of 2. 2016-08-22 10:23:25 -07:00
.vscode Add typescript and typings as devDependencies and use npm scripts for install, build, and test related actions to prevent need for global dependencies 2016-08-05 13:46:48 -07:00
src Setup tslint on build and test to enforce good practices and consistent style. 2016-08-22 10:22:50 -07:00
test Setup tslint on build and test to enforce good practices and consistent style. 2016-08-22 10:22:50 -07:00
.gitignore Add gulp ghpages task to deploy docs to gh-pages 2016-07-13 10:38:52 -07:00
.travis.yml Add typescript and typings as devDependencies and use npm scripts for install, build, and test related actions to prevent need for global dependencies 2016-08-05 13:46:48 -07:00
CONTRIBUTING.md Add typescript and typings as devDependencies and use npm scripts for install, build, and test related actions to prevent need for global dependencies 2016-08-05 13:46:48 -07:00
LICENSE Initial Commit. Setup powerbi-router project with build and tests 2016-06-23 13:12:39 -07:00
README.md Update README.md with fixed badge image, documentation link, and description of wildcard routes. 2016-08-05 16:33:49 -07:00
gulpfile.js Auto-format all files to use consistent tab size of 2. 2016-08-22 10:23:25 -07:00
karma.conf.js Auto-format all files to use consistent tab size of 2. 2016-08-22 10:23:25 -07:00
package.json Setup tslint on build and test to enforce good practices and consistent style. 2016-08-22 10:22:50 -07:00
tsconfig.json Auto-format all files to use consistent tab size of 2. 2016-08-22 10:23:25 -07:00
tslint.json Setup tslint on build and test to enforce good practices and consistent style. 2016-08-22 10:22:50 -07:00
typings.json Add route-recognizer and restructure tests. 2016-06-23 13:12:39 -07:00
webpack.config.js Change webpack.config to enforce using package name as library name 2016-06-28 14:51:13 -07:00
webpack.test.config.js Rename tsconfig and webpack configs related to testing to be consistent with type of test and other projects. Add task to generate custom dts with no exports 2016-06-23 13:12:39 -07:00
webpack.test.tsconfig.json Auto-format all files to use consistent tab size of 2. 2016-08-22 10:23:25 -07:00

README.md

powerbi-router

Build Status NPM Version NPM Total Downloads NPM Monthly Downloads GitHub tag

Router for Microsoft Power BI. Given an http method and url pattern call the matching handler with the request and response object. Syntax matches common libraries such as express and restify. This library uses Route-recognizer to handle pattern matching such as /root/path/:name where name will be passed as paramter to the handler.

Documentation:

https://microsoft.github.io/powerbi-router

Installation:

npm install --save powerbi-router

Usage:

import * as Wpmp from 'window-post-message-proxy';
import * as Router from 'powerbi-router';

const wpmp = new Wpmp.WindowPostMessageProxy();
const router = new Router.Router(wpmp);

/**
 * Demonstrate 'syncrhonous' API with request and response.
 */
router.get('/report/pages', (request, response) => {
  return app.getPages()
    .then(pages => {
      response.send(200, pages);
    });
});

/**
 * Demonstrate 'asynchronous' API with accepted command, and events
 */
router.put('/report/pages/active', (request, response) => {
  const page = request.body;

  return app.validatePage(page)
    .then(() => {
      app.setPage(request.body)
        .then(page => {
          hpm.post(`/report/${reportId}/events/pageChanged`, page);
        }, error => {
          hpm.post(`/report/${reportId}/events/error`, error);
        });

      response.send(202);
    }, errors => {
      response.send(400, errors);
    });
});

/**
 * Demonstrate using path parameters and query parameters
 */
router.put('/report/pages/:pageName/visuals?filter=true', (request, response) => {
  const pageName = request.params.pageName;
  const filter = request.queryParams.filter;

  return app.validatePage(pageName)
    .then(() => {
      return app.getVisuals(filter)
        .then(visuals => {
          response.send(200, visuals);
        }, error => {
          response.send(500, error);
        });
    }, errors => {
      response.send(400, errors);
    });
});

/**
 * Demonstrate using wildcard matching
 */
router.get('*notfound', (request, response) => {
  response.send(404, `Not Found. Url: ${request.params.notfound} was not found.`);
});