-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add an option to use functional response transformer * Update dependencies * Fix class transformer returing undefined instead of transformed object * Update README.md * Add an option to use functional request interceptor * Update README.md * Bump version * Fix request interceptor tests * Add an option to make concurrent requests * Add ResponseInspector to inspect HTTP response * Change name to display as multiple * Add name to TailorFetchResponse and change how ResponseInspector.ts accesses it * update README.md * release v1.7.0 --------- Co-authored-by: Marek Dev <[email protected]> Co-authored-by: Marek home Home <[email protected]>
- Loading branch information
1 parent
3a4623f
commit 07470d7
Showing
9 changed files
with
460 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import TailorResponse from "../Response"; | ||
|
||
export default class ResponseInspector { | ||
|
||
constructor() { | ||
// Maybe later | ||
} | ||
|
||
private static output = (response: TailorResponse) => { | ||
console.log('----------------------BEGIN RESPONSE INSPECTOR--------------------------'); | ||
|
||
if (response.successful()) { | ||
console.log(` Request Name: ${response.name ?? 'Unknown'}`); | ||
console.log(` Status: ${response.status}`); | ||
console.log(` Headers: ${JSON.stringify(response.headers, null, 2)}`); | ||
console.log(` Data: ${JSON.stringify(response.data, null, 2)}`); | ||
} | ||
|
||
if (response.failed()) { | ||
console.error(` Request Name: ${response.name ?? 'Unknown'}`); | ||
console.error(` Error: Response failed`); | ||
console.error(` Status: ${response.status}`); | ||
console.error(` Headers: ${JSON.stringify(response.headers, null, 2)}`); | ||
console.error(` Data: ${JSON.stringify(response.data, null, 2)}`); | ||
} | ||
|
||
console.log('----------------------END RESPONSE INSPECTOR-----------------------------') | ||
} | ||
|
||
static inspectSingle = (response: TailorResponse) => { | ||
ResponseInspector.output(response); | ||
} | ||
|
||
static inspectMultiple = (responses: TailorResponse[])=> { | ||
responses.forEach((response: TailorResponse) => { | ||
ResponseInspector.output(response); | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {describe} from "node:test"; | ||
import TailorFetch, {TailorResponse} from "../src"; | ||
import {assert} from "chai"; | ||
|
||
describe('make concurrent requests', () => { | ||
it('should make concurrent requests', async () => { | ||
|
||
// Arrange: Set up the test by defining the URL and request options | ||
const responses: TailorResponse[] = await TailorFetch.concurrent([ | ||
{url: 'https://dummyjson.com/products', method: 'GET', options: {name: 'products', json: true}}, | ||
{url: 'https://dummyjson.com/products/1', method: 'GET', options: {name: 'product', json: true}}, | ||
{url: 'https://dummyjson.com/carts', method: 'GET', options: {name: 'carts', json: true}}, | ||
]); | ||
|
||
// Check if the response is successful (status code 2xx). | ||
assert.equal(responses.length, 3, "Failed to make all requests"); | ||
|
||
// Check if response is an instance of TailorResponse | ||
assert.instanceOf(responses, Array); | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters