Serve JSONP in Dyson

Dyson is a great fake JSON server written in JavaScript/Node.JS.

In my current pet project, I have a fake Strava API server. Strava REST API allows you to use JSONP to overcome cross-domain restrictions. You have to add a callback parameter to the query string.

To simulate it with Dyson, you have to override the render method of the Express middleware in the endpoint definition. In my solution, depending on the existence of the callback parameter, I return either raw JSON response or I wrap it with the provided callback:

Advertisements