Replies: 2 comments 1 reply
-
|
Hi, @bikasv. Thanks for opening this. From what I can gather, JSONP is a response handling format. This is something your request client should do (receive the response, parse it, invoke the right callback, etc). You can already mock JSON responses with MSW, and I believe that includes responses in a JSONP format. http.get('/resource', () => {
return new HttpResponse(yourJsonP, { headers: { 'content-type': 'application/json' } })
})The only catch here is that JSONP objects aren't actual valid JSON (i.e. Hope this helps! |
Beta Was this translation helpful? Give feedback.
-
|
Sorry for getting back here extremely late, but if anyone wants to try JSONP response, here's the syntax for it - http.all('URL', ({ request }) => {
const { searchParams } = new URL(request.url);
const callback = searchParams.get('callback');
const jsonp = `${callback}(${JSON.stringify(JSONP_RESPONSE_DATA)})`;
return new HttpResponse(jsonp, { headers: { 'Content-Type': 'application/javascript' } });
}); |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Scope
Adds a new behavior
Compatibility
Feature description
Hi,
We've a requirements where we've a few APIs fetched from jsonp calls. While express supports jsonp, msw doesn't. Is it possible to add the support?
Beta Was this translation helpful? Give feedback.
All reactions