I've built a proxy server that handles development requests and ensures that API calls are hammered in testing. This is how I do it with my ASP.Net MVC proxy:
public ActionResult ProxyRequest(string url, string request)
{
object cachedRequest = Cache[url];
if(cachedRequest != null)
{
return Content(cachedRequest, "application/json");
}
else
{
// make the http request here
Cache[url] = cachedRequest;
return Content(cachedRequest, "application/json");
}
}
I'm not on my development box right now so I'm doing this off the top off my head, but the concept is the same. Instead of using Cache[url] = cachedRequest I use a Cache.Insert method but that has a lot of parameters that I couldn't remember. (got lazy and built a wrapper class around it so I don't have to remember it)
This setup proxies all of my JSON requests (using a var isDevelopment = true
(|| false)) in my JS code and using the isDevelopment variable know whether or not to proxy the request or hit the server directly.