Welcome!

APIs for the Internet of Things

Max Katz

Subscribe to Max Katz: eMailAlertsEmail Alerts
Get Max Katz via: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn


Blog Feed Post

Updated With More Elegant Code: Invoking Uber REST API From Server Code

Screen Shot 2015-10-14 at 2.50.55 PM

Invoking Uber API

Last Friday I blogged how to invoke Uber REST API from the server. I was looking at Uber documentation and realized there is a better and more elegant way to invoke the API. Uber specifically provides a server token. Instead of using a header parameter, I have updated the script to use the server token. This is how the code looks now:

// service input
var lat = request.get("lat");
var lng = request.get("lng");
var url = "https://api.uber.com/v1/products";
var token = "4dPYezRBsWmqpV_XOyhIb2lndGsRfJaYhhXvJBRY";

var parameters = {
  "server_token": token,
  "latitude": lat,
  "longitude": lng
};

// send Ajax request
var res = XHR2.send("GET", url, {
  parameters
});
  
// response
response.success(res, "application/json");

Also, instead of attaching the parameters to the URL, the script creates parameters object with all the inputs for the API. This script is more elegant and simpler to understand.


Read the original blog entry...

More Stories By Max Katz

Max Katz heads Developer Relations for Appery.io, a cloud-based mobile app platform. He loves trying out new and cool REST APIs in mobile apps. Max is the author of two books “Practical RichFaces” (Apress 2008, 2011), DZone MVB (Most Valuable Blogger), and is a frequent speaker at developer conferences. You can find out what Max is up to on his blog: http://maxkatz.org and Twitter: @maxkatz.