From 336ab5c263d8aec49b1e7ddb42efc64ca7b5ab1a Mon Sep 17 00:00:00 2001 From: Abhishek P Anil Date: Wed, 24 Apr 2024 11:46:42 +0530 Subject: [PATCH] Changed the reconciliation service request method to post,added the respective payload.closes #1 --- src/ReconciliationService.js | 6 +++++- src/TestBench.js | 4 ++-- src/utils.js | 25 +++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/ReconciliationService.js b/src/ReconciliationService.js index 77f3bf4..8dbd85a 100644 --- a/src/ReconciliationService.js +++ b/src/ReconciliationService.js @@ -1,5 +1,5 @@ -import { fetchJsonpParams, fetchParams } from './utils.js'; +import { fetchJsonpParams, fetchParams , postParams , postJsonpParams } from './utils.js'; import { specVersions } from './JsonSchemas.js'; import { getSchema } from './JsonValidator.js'; @@ -24,6 +24,10 @@ export default class ReconciliationService { getFetcher() { return this.cors ? fetchParams : fetchJsonpParams; } + + postFetcher() { + return this.cors ? postParams : postJsonpParams; + } } diff --git a/src/TestBench.js b/src/TestBench.js index fc2d3d3..30d7270 100644 --- a/src/TestBench.js +++ b/src/TestBench.js @@ -112,8 +112,8 @@ export default class TestBench extends React.Component { return; } this.setState({reconResults: 'fetching'}); - let fetcher = this.props.service.getFetcher(); - fetcher(this.formulateQueryUrl(), {timeout: 20000}) + let fetcher = this.props.service.postFetcher(); + fetcher({url:this.props.service.endpoint,queries:JSON.stringify({q0: this.formulateReconQuery()})}) .then(result => result.json()) .then(result => this.setState({ diff --git a/src/utils.js b/src/utils.js index f360d8d..a48fce1 100644 --- a/src/utils.js +++ b/src/utils.js @@ -17,6 +17,31 @@ export const fetchParams = (baseUrl, params) => { return fetch(addParams(baseUrl, params)); } +export const postJsonpParams = ({url,queries}) => { + return fetchJsonp(url, { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' + }, + body: new URLSearchParams({ + queries + }) + }); +} + + +export const postParams = ({url,queries}) => { + return fetch(url, { + method:"POST", + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' + }, + body: new URLSearchParams({ + queries + }) +}); +} + export const jsonTheme = { scheme: 'monokai', author: 'wimer hazenberg (http://www.monokai.nl)',