A generic messaging component to send HTTP style message payloads over the window.postMessage API. Requires an implementation of window postMessage proxy such as 'window-post-message-proxy'
Перейти к файлу
Or Shemesh dd05dcf5b8
Merge pull request #4 from microsoft/readme_support_links
Update README.md with correct support links
2024-10-14 16:43:03 +03:00
.pipelines Merged PR 91212: [CDPx pipeline]: Fixed static analysis 2020-09-23 11:39:28 +00: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 14:00:42 -07:00
src Setup tslint on build and test to enforce good practices and consistent style. 2016-08-22 11:11:45 -07:00
test Setup tslint on build and test to enforce good practices and consistent style. 2016-08-22 11:11:45 -07:00
.gitignore Merged PR 115321: Upgraded Gulp to v4 to fix build on Node v12 2020-09-23 07:34:01 +00:00
.travis.yml Add npm deploy configuration to .travis.yml 2016-08-05 14:56:05 -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 14:00:42 -07:00
LICENSE Initial Commit. Add HttpPostMessage class with build and test setup. 2016-05-13 13:14:46 -07:00
README.md Update README.md with correct support links 2024-10-14 15:03:36 +03:00
SECURITY.md Merged PR 144012: Added SECURITY.md 2021-02-03 09:01:31 +00:00
gulpfile.js Merged PR 115321: Upgraded Gulp to v4 to fix build on Node v12 2020-09-23 07:34:01 +00:00
karma.conf.js Auto-format all files to use consistent tab size of 2. 2016-08-22 11:12:58 -07:00
package.json Merge remote-tracking branch 'internalADO/master' into gh-mirror 2021-02-12 11:03:43 +05:30
tsconfig.json Auto-format all files to use consistent tab size of 2. 2016-08-22 11:12:58 -07:00
tslint.json Setup tslint on build and test to enforce good practices and consistent style. 2016-08-22 11:11:45 -07:00
typings.json Change build to use webpack as umd library and add gulp task to generate custom dts without exports 2016-06-17 13:15:26 -07:00
webpack.config.js Change web.config to enforce using package name as library name 2016-06-28 14:48:07 -07:00
webpack.test.config.js Change build to use webpack as umd library and add gulp task to generate custom dts without exports 2016-06-17 13:15:26 -07:00
webpack.test.tsconfig.json Auto-format all files to use consistent tab size of 2. 2016-08-22 11:12:58 -07:00

README.md

htt-post-message

Travis branch npm Total Downloads Monthly Downloads GitHub tag

A generic messaging component to send HTTP style message payloads over the window.postMessage API. Requires an implementation of window postMessage proxy such as 'window-post-message-proxy'.

Documentation:

https://microsoft.github.io/http-post-message

Installation

npm install --save http-post-message

Usage

The HttpPostMessage takes in an object that implements the IPostMessage interface which is just one method postMessage which returns a Promise.

In the case below we created a mock postMessage proxy, but in normal usage you would likely use the accompanying library window-post-message-proxy and configure it to handle http messages as shown in the section below

import * as hpm from 'http-post-message';

const stubWindowPostMessageProxy: hpm.IPostMessage = {
  postMessage(message: any) {
    console.log(message);
    return Promise.resolve(message):
  }
}

const httpPostMessage = new hpm.HttpPostMessage(stubWindowPostMessageProxy);

httpPostMessage.get('target/path')
  .then(response => {
    ...
  });

Methods

The object supports all the standard http methods, get, post, put, patch, and delete. You can also send an IRequest object directly to the lower-level send method.

Determining promise resolution state

The promise returned by the request will be fulfulled or rejected depending on how the instance of WindowPostMessageProxy provided to the constructor was configured.

Since we intend to use HTTP semantics, this library comes with static methods that can be provided to the WPMP class during construction as seen below:

import * as wpmp from 'window-post-message-proxy';
import * as hpm from 'http-post-message';

const windowPostMessageProxy = new wpmp.WindowPostMessageProxy({
  processTrackingProperties: {
      addTrackingProperties: hpm.HttpPostMessage.addTrackingProperties,
      getTrackingProperties: hpm.HttpPostMessage.getTrackingProperties,
  },
  isErrorMessage: hpm.HttpPostMessage.isErrorMessage
});

const httpPostMessage = new hpm.HttpPostMessage(windowPostMessageProxy);

Default Headers and Default Window

You may specify default headers and default target window to be sent with every request by supplying them during construction.

Providing the default target window in the constructor means you do not have to specify it in each individual request, but it can be over written to allow a single instance of HPM to communicate with multiple windows.

import * as hpm from 'http-post-message';

...

const httpPostMessage = new hpm.HttpPostMessage(wpmp, {
    'x-sdk-type': sdkType,
    'x-sdk-version': sdkVersion
  }, defaultTargetWindow);
});

Support

  • Feature Requests: Submit your ideas and suggestions to the Fabric Ideas Portal, where you can also vote on ideas from other developers.
  • Bug Reports and Technical Assistance: Visit the Fabric Developer Community Forum. Our team and community experts are ready to assist you.
  • Additional Support: Contact your account manager or reach out to the Fabric Support Team.