31917b68cc | ||
---|---|---|
.vscode | ||
src | ||
test | ||
.gitignore | ||
.travis.yml | ||
CONTRIBUTING.md | ||
LICENSE | ||
README.md | ||
gulpfile.js | ||
karma.conf.js | ||
package.json | ||
tsconfig.json | ||
typings.json | ||
webpack.config.js | ||
webpack.test.config.js | ||
webpack.test.tsconfig.json |
README.md
htt-post-message
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'.
Installation
npm install -g 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.
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.