Giter VIP home page Giter VIP logo

hashagna's Introduction

hashagna

The Final and definitive solution to handle 302+Location -> Hash pattern

NPM Version NPM Downloads Dependency status Dev dependency status Quality Gate Coverage Maintainability Reliability Build Status LICENSE Blog Buy me a coffee

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

JsDocs @ GitHub Pages

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

  • Chromium 86.0.4217.0 (Chrome & Edge)
  • Firefox 80.0b8
  • Webkit 14 (Safari)
  • Internet Explorer 11.1016.18362.0

๐Ÿ“œ LICENSE

MIT License

๐Ÿ“ AUTHOR

Marco Ricupero

hashagna's People

Contributors

marketto avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.