SahamatiNet
  • Background
  • SahamatiNet POC
    • Introduction
    • Applications
    • Observability
    • Integration Steps
      • Sandbox Onboarding
      • IAM APIs
      • CR APIs
      • Integration with Router
        • Sample Code Snippets
          • Python
          • Java
          • JavaScript
          • GoLang
          • C#
        • Router APIs Specifications
          • FIU API Specification
          • AA API Specification
          • FIP API Specification
      • ReBIT Workflows using Router
        • Account Discovery & Linking
        • Consent Workflow
        • FI Request Workflow
    • Integration with Simulators
      • AA Simulator
      • FIP Simulator
      • FIU Simulator
    • Validation of Integration
  • Glossary
  • Guidelines
  • Frequently Asked Questions
  • How To Guides
    • How To Onboard to Sandbox ?
    • How To Decide on an Entity ID ?
    • How To Generate a Certificate ?
    • How To Generate Tokens ?
Powered by GitBook
LogoLogo

Copyright © 2025 - Sahamati Foundation

On this page

Was this helpful?

Export as PDF
  1. SahamatiNet POC
  2. Integration Steps
  3. Integration with Router
  4. Sample Code Snippets

JavaScript

Without Router - Current Approach
// Assuming this as previous logic without Router
const axios = require('axios');

const entityMetadataFromCR = {
    baseUrl: 'http://fip-1.dev.sahamati.org.in/fip-simulate',
    id: "FIP-SIMULATOR"
}

const getHttpConfig = ({ baseUrl, route, headers, data, methodType }) => {
    return { url: `${baseUrl}${route}`, headers: headers, data, methodType };
};

const executeDiscoveryRequest = () => {
    const route = '/v2/Accounts/discover';

    const config = getHttpConfig({ baseUrl: entityMetadataFromCR.baseUrl, route, headers: {}, data: {}, methodType: 'POST' });

    axios.request(config)
        .then(response => response.data)
        .catch(error => {
            console.error('Error making discovery request:', error.message);
            throw error;
        });

};

const performAnotherOperations = async (accountDiscoverResponse) => {
    console.log('Perform another operations with the response', accountDiscoverResponse);
}

executeDiscoveryRequest()
    .then(performAnotherOperations)
    .then(() => console.log('Account discovery successful.'))
    .catch(() => console.log('Account discovery failed.'))
    .finally(() => console.log('Account discovery completed.'));

With Router Integration
// Changes to implementation to integrate with Router
const axios = require('axios');

// OLD START

const entityMetadataFromCR = {
    baseUrl: 'http://fip-1.dev.sahamati.org.in/fip-simulate',
    id: "FIP-SIMULATOR"
}

const getHttpConfig = ({ baseUrl, route, headers, data, methodType }) => {
    return { url: `${baseUrl}${route}`, headers: headers, data, methodType };
};

const executeDiscoveryRequest = () => {
    const route = '/v2/Accounts/discover';
    
    let config = getHttpConfig({ baseUrl: entityMetadataFromCR.baseUrl, route, headers: {}, data: {}, methodType: 'POST' });

    // add Sahamati configuration [Start]
    config = addSahamatiConfiguration({ config, route });
    // add Sahamati configuration [End]

    axios.request(config)
        .then(response => response.data)
        .catch(error => {
            console.error('Error making discovery request:', error.message);
            throw error;
        });
};

const performAnotherOperations = async (accountDiscoverResponse) => {
    console.log('Perform another operations with the response', accountDiscoverResponse);
}

executeDiscoveryRequest()
    .then(performAnotherOperations)
    .then(() => console.log('Account discovery successful.'))
    .catch(() => console.log('Account discovery failed.'))
    .finally(() => console.log('Account discovery completed.'));


// OLD END


// NEW START
  
const generateBase64EncodedJson = (json) => {
    return btoa(JSON.stringify(json));
}

const generateRequestMeta = (recipientId) => {
    const context = { "recipient-id": recipientId }
    return generateBase64EncodedJson(context);
}

const addSahamatiConfiguration = ({ config, route }) => {
    const routerUrl = 'http://api.dev.sahamati.org.in/fip-router';
    config.url = `${routerUrl}${route}`;
    config.headers["x-request-meta"] = generateRequestMeta(entityMetadataFromCR.id);
    return config;
}

// NEW END

PreviousJavaNextGoLang

Last updated 26 days ago

Was this helpful?