# powerbi-router

> 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.

Latest version **0.1.5** (published 2016-08-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install powerbi-router
pnpm add powerbi-router
yarn add powerbi-router
bun add powerbi-router
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.5 |
| Published | 2016-08-29 |
| First published | 2016-06-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Microsoft Power BI Team |
| Maintainers | powerbi |
| Keywords | microsoft, powerbi, router |

## Links

- npm: https://www.npmjs.com/package/powerbi-router
- Repository: https://github.com/Microsoft/powerbi-router
- Homepage: https://github.com/Microsoft/powerbi-router#readme
- Issues: https://github.com/Microsoft/powerbi-router/issues
- npm.io page: https://npm.io/package/powerbi-router

## Dependencies (2)

- [es6-promise](https://npm.io/package/es6-promise.md) ^3.2.1
- [route-recognizer](https://npm.io/package/route-recognizer.md) ^0.1.11

## Alternatives

- [express-promise-router](https://npm.io/package/express-promise-router.md) — 736.1K weekly downloads
- [next-usequerystate](https://npm.io/package/next-usequerystate.md) — 29.8K weekly downloads
- [@bitkyc08/opencodex](https://npm.io/package/@bitkyc08/opencodex.md) — 4.6K weekly downloads
- [lynkr](https://npm.io/package/lynkr.md) — 575 weekly downloads
- [baremetal.js](https://npm.io/package/baremetal.js.md) — 42 weekly downloads

## Recent versions

- 0.1.5 (latest) — 2016-08-29
- 0.1.4 — 2016-08-27
- 0.1.2 — 2016-07-13
- 0.1.1 — 2016-06-24
- 0.1.0 — 2016-06-23

## README

# powerbi-router
[![Build Status](https://img.shields.io/travis/Microsoft/powerbi-router.svg)](https://travis-ci.org/Microsoft/powerbi-router)
[![NPM Version](https://img.shields.io/npm/v/powerbi-router.svg)](https://www.npmjs.com/package/powerbi-router)
[![NPM Total Downloads](https://img.shields.io/npm/dt/powerbi-router.svg)](https://www.npmjs.com/package/powerbi-router)
[![NPM Monthly Downloads](https://img.shields.io/npm/dm/powerbi-router.svg)](https://www.npmjs.com/package/powerbi-router)
[![GitHub tag](https://img.shields.io/github/tag/microsoft/powerbi-router.svg)](https://github.com/Microsoft/powerbi-router/tags)

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](https://github.com/tildeio/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](https://microsoft.github.io/powerbi-router)

## Installation:

```bash
npm install --save powerbi-router
```

## Usage:

```typescript
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.`);
});
```

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