diff --git a/README.md b/README.md index cfda766..3239a64 100644 --- a/README.md +++ b/README.md @@ -168,6 +168,7 @@ Options: |Parameter|type|mandatory|description| |---------|----|---------|-----------| |`container`|`boolean`|no|Default true, when false, renders a component without its container| +|`httpMethod`|`string`|no|Default GET, when false, Allows you specify which HTTP method to use. Available options: GET or POST. Note: If you have more than one component, POST is automatically forced.| |`disableFailoverRendering`|`boolean`|no|Disables the automatic failover rendering in case the registry times-out (in case configuration.registries.clientRendering contains a valid value.) Default false| |`forwardAcceptLanguageToClient`|`boolean`|no|When not specified in config, defaults to false. When true, when doing client-side requests (normal or failover) appends a custom parameter to the browser's component hrefs so that the framework will ignore the browser's Accept-Language in favour of the query-string value| |`headers`|`object`|no|An object containing all the headers that must be forwarded to the component| diff --git a/src/get-components-data.js b/src/get-components-data.js index b954060..2799eca 100644 --- a/src/get-components-data.js +++ b/src/get-components-data.js @@ -141,8 +141,15 @@ module.exports = function(config) { return cb(serverRenderingFail); } - const performRequest = - serverRendering.components.length === 1 ? performGet : performPost; + let componentsLength = serverRendering.components.length; + let performRequest = componentsLength === 1 ? performGet : performPost; + + const method = (options.httpMethod || '').toLowerCase(); + if (method === 'post') { + performRequest = performPost; + } else if (method === 'get') { + performRequest = componentsLength > 1 ? performPost : performGet; + } performRequest( serverRenderingEndpoint, diff --git a/test/unit/client-get-component-data.js b/test/unit/client-get-component-data.js index 88e0960..b430cc0 100644 --- a/test/unit/client-get-component-data.js +++ b/test/unit/client-get-component-data.js @@ -15,6 +15,7 @@ describe('client : get-component-data', () => { const options = { parameters: { p1: 'v1', p2: 'v2' }, headers: { 'header-a': 'header-value b' }, + httpMethod: 'POST', timeout: 10 }; @@ -90,6 +91,7 @@ describe('client : get-component-data', () => { const options = { parameters: { p1: 'v1', p2: 'v2' }, headers: { 'header-a': 'header-value b' }, + httpMethod: 'GET', timeout: 10 };