Developer Talk: Making Ajax Requests to Pro APIs

Getting questions from developers using our products is part of what makes my job so rewarding. Recently I received this one from a developer, “Can we make an Ajax request to Whitepages Pro APIs?” For anyone unfamiliar with Ajax, it’s a group of technologies that allow users to send and retrieve data from the server without needing to reload the entire page. The answer is a little complicated, but I’ll answer it today with this post.

The reason why making an Ajax request directly to Pro API is somewhat tricky has to do with the fact that the request URL contains the API key. It becomes a security implication to enable Ajax requests because our API key would be exposed on the client side. Because of that, we do not provide any of the JSONP or CORS options.

Instead, the workaround is to use the Web application server as an intermediary. Now the Ajax request flows to the origin server’s Web method and from there it goes to make a request to Pro APIs.

Here’s a visual to help explain:


This setup ensures that the API key is not compromised or exposed on the client side. There might be a slight latency due to the extra hop, but because Pro APIs’ response time is so fast, there should be no significant lag.

A C# sample implementing this flow can be found here. The sample takes in a phone number and displays whom this phone belongs to.

What do you think? Do you have any interesting ideas on using Whitepages Pro APIs via Ajax requests in your Web applications? Let me know at kshah [at] whitepages [dot] com and be sure to visit our Developer Center to learn more about Pro APIs.


Thanks for reading! You might be interested in these posts, too: