rest-api-handler
Advanced tools
Comparing version 1.1.2 to 1.2.0
@@ -5,2 +5,7 @@ # Change Log | ||
## [1.2.0] 2018-03-15 | ||
### Changed | ||
- Better response decoding. If content type is not json or text, blob will be returned. | ||
## [1.1.1] 2018-02-08 | ||
@@ -7,0 +12,0 @@ ### Fixed |
@@ -7,10 +7,16 @@ 'use strict'; | ||
* @param {Response} response - Native response. | ||
* @returns {Object | string} Decoded json or simple string. | ||
* @returns {DecodedStream} Decoded json or simple string. | ||
*/ | ||
function decodeResponse(response) { | ||
if (response.headers.get('content-type').indexOf('application/json') !== -1) { | ||
var contentType = response.headers.get('content-type'); | ||
if (contentType.indexOf('json') >= 0) { | ||
return response.json(); | ||
} | ||
return response.text(); | ||
if (contentType.indexOf('text') >= 0) { | ||
return response.text(); | ||
} | ||
return response.blob(); | ||
} | ||
@@ -24,2 +30,3 @@ | ||
*/ | ||
var responseProcessor = (function (response) { | ||
@@ -26,0 +33,0 @@ return decodeResponse(response).then(function (decodedResponse) { |
@@ -7,10 +7,16 @@ 'use strict'; | ||
* @param {Response} response - Native response. | ||
* @returns {Object | string} Decoded json or simple string. | ||
* @returns {DecodedStream} Decoded json or simple string. | ||
*/ | ||
function decodeResponse(response) { | ||
if (response.headers.get('content-type').indexOf('application/json') !== -1) { | ||
var contentType = response.headers.get('content-type'); | ||
if (contentType.indexOf('json') >= 0) { | ||
return response.json(); | ||
} | ||
return response.text(); | ||
if (contentType.indexOf('text') >= 0) { | ||
return response.text(); | ||
} | ||
return response.blob(); | ||
} | ||
@@ -24,2 +30,3 @@ | ||
*/ | ||
var responseProcessor = (function (response) { | ||
@@ -26,0 +33,0 @@ return decodeResponse(response).then(function (decodedResponse) { |
@@ -412,10 +412,16 @@ /** | ||
* @param {Response} response - Native response. | ||
* @returns {Object | string} Decoded json or simple string. | ||
* @returns {DecodedStream} Decoded json or simple string. | ||
*/ | ||
function decodeResponse(response) { | ||
if (response.headers.get('content-type').indexOf('application/json') !== -1) { | ||
var contentType = response.headers.get('content-type'); | ||
if (contentType.indexOf('json') >= 0) { | ||
return response.json(); | ||
} | ||
return response.text(); | ||
if (contentType.indexOf('text') >= 0) { | ||
return response.text(); | ||
} | ||
return response.blob(); | ||
} | ||
@@ -429,2 +435,3 @@ | ||
*/ | ||
var responseProcessor = (function (response) { | ||
@@ -431,0 +438,0 @@ return decodeResponse(response).then(function (decodedResponse) { |
@@ -418,10 +418,16 @@ (function (global, factory) { | ||
* @param {Response} response - Native response. | ||
* @returns {Object | string} Decoded json or simple string. | ||
* @returns {DecodedStream} Decoded json or simple string. | ||
*/ | ||
function decodeResponse(response) { | ||
if (response.headers.get('content-type').indexOf('application/json') !== -1) { | ||
var contentType = response.headers.get('content-type'); | ||
if (contentType.indexOf('json') >= 0) { | ||
return response.json(); | ||
} | ||
return response.text(); | ||
if (contentType.indexOf('text') >= 0) { | ||
return response.text(); | ||
} | ||
return response.blob(); | ||
} | ||
@@ -435,2 +441,3 @@ | ||
*/ | ||
var responseProcessor = (function (response) { | ||
@@ -437,0 +444,0 @@ return decodeResponse(response).then(function (decodedResponse) { |
{ | ||
"name": "rest-api-handler", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"description": "Handler for REST APIs", | ||
@@ -9,3 +9,3 @@ "main": "dist/rest-api-handler.js", | ||
"scripts": { | ||
"js-lint": "node node_modules/eslint/bin/eslint.js --ext .js ./src", | ||
"js-lint": "node node_modules/eslint/bin/eslint.js --ext .js ./src ./test", | ||
"js-lint-export": "npm run js-lint -- -o ./test_results/checkstyle/js-checkstyle.xml -f checkstyle", | ||
@@ -36,3 +36,3 @@ "flow": "node node_modules/flow-bin/vendor/flow", | ||
"eslint-config-socifi": "1.x", | ||
"flow-bin": "0.64.0", | ||
"flow-bin": "0.67.1", | ||
"flow-coverage-report": "^0.3.0", | ||
@@ -39,0 +39,0 @@ "jasmine-core": "^2.5.2", |
@@ -0,0 +0,0 @@ # REST API Handler |
@@ -18,3 +18,7 @@ // @flow | ||
*/ | ||
export default function resolveArray<Input, Processors: Array<ProcessorAdapter>>(response: Input, list: Processors, i: number = 0): Promise<any> { | ||
export default function resolveArray<Input, Processors: Array<ProcessorAdapter>>( | ||
response: Input, | ||
list: Processors, | ||
i: number = 0, | ||
): Promise<any> { | ||
const processor: ?ProcessorAdapter = list[i]; | ||
@@ -21,0 +25,0 @@ |
@@ -8,4 +8,6 @@ // @flow | ||
export type ProcessedResponse = ApiResponseType<Object | string>; | ||
type DecodedStream = Blob | Object | string; | ||
export type ProcessedResponse = ApiResponseType<DecodedStream>; | ||
/** | ||
@@ -15,10 +17,16 @@ * Decode API body response. | ||
* @param {Response} response - Native response. | ||
* @returns {Object | string} Decoded json or simple string. | ||
* @returns {DecodedStream} Decoded json or simple string. | ||
*/ | ||
function decodeResponse(response: Response): Promise<Object | string> { | ||
if (response.headers.get('content-type').indexOf('application/json') !== -1) { | ||
function decodeResponse(response: Response): Promise<DecodedStream> { | ||
const contentType = response.headers.get('content-type'); | ||
if (contentType.indexOf('json') >= 0) { | ||
return response.json(); | ||
} | ||
return response.text(); | ||
if (contentType.indexOf('text') >= 0) { | ||
return response.text(); | ||
} | ||
return response.blob(); | ||
} | ||
@@ -34,3 +42,3 @@ | ||
return decodeResponse(response) | ||
.then((decodedResponse: Object | string) => { | ||
.then((decodedResponse: DecodedStream) => { | ||
// create custom response format | ||
@@ -37,0 +45,0 @@ const toRespond: ProcessedResponse = { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
78795
1868