@marketto/hashagna
v1.1.0
Published
Utility to handle (GET or POST) APIs which redirects (3xx) to an uri appending Hash params via iFrame
Downloads
13
Maintainers
Readme
hashagna
The Final and definitive solution to handle 302+Location -> Hash pattern
Utility to handle (GET or POST) APIs which redirects (3xx) to an uri appending Hash params via iFrame
🔌 INSTALLATION
npm i -s @marketto/hashagna
🔧 USAGE
MJS / ES6 / Typescript
import { HashagnaHttpClient } from '@marketto/hashagna';
AMD
require(['/dist/hashagna.min.js'], ({ HashagnaHttpClient }) => {
// your code
});
Script
<!-- Polyfills needed only to support IE11 -->
<script crossorigin="anonymous" src="https://polyfill.io/v3/polyfill.min.js?version=3.52.1&features=Object.entries%2CPromise%2CElement.prototype.remove"></script>
<script src="https://unpkg.com/@marketto/hashagna@latest/dist/hashagna.min.js"></script>
💻 DEMO
npm run manual-test
📖 DOCUMENTATION
HashagnaHttpClient
Class with static methods
Both get and post methods accepts 2 mandatory params and an optional 3rd one:
- url - relative or absolute path of the api
- params - (Object) Key/Value of params to be sent
- options (optional)
- iFrame - DOM Element to use
- iFrameId - id of the iFrame to use
- autoClean - (only with iFrame or iFrameId) if true the iframe will be wiped up after receiving data
Both get and post methods are async and returns and object containing the following:
- hash: string
- hashParams: Object
- host: string
- hostname: string
- href: string
- origin: string
- pathname: string
- protocol: string
- search: string
- port: string
- query: Object
GET
HashagnaHttpClient.get('/api/auto-redirect', { code: '2345', userId: 'user id' })
.then(({ hashParams }) => {
console.log(hashParams); // {key: value, ...}
})
.catch(err => {
// Handle your error
});
POST
HashagnaHttpClient.post('/another-api', { clientAuth: 'askjf' })
.then(({ hashParams }) => { // {key: value, ...}
console.log(hashParams.auth);
})
.catch(err => {
// Handle your error
});
🔃 Compatibility
- [X] Chromium 86.0.4217.0 (Chrome & Edge)
- [X] Firefox 80.0b8
- [X] Webkit 14 (Safari)
- [X] Internet Explorer 11.1016.18362.0