Skip to content

Instantly share code, notes, and snippets.

@getjump
Created October 28, 2015 12:00
Show Gist options
  • Select an option

  • Save getjump/0728fdd95fd39dc71e2e to your computer and use it in GitHub Desktop.

Select an option

Save getjump/0728fdd95fd39dc71e2e to your computer and use it in GitHub Desktop.
BASE_URL = 'http://our_app/api/'
string getRequestURL(string apiMethod)
{
return BASE_URL + apiMethod;
}
T request<T>(string apiMethod = 'lockbox/list', enum {GET, POST, PUT, ...} httpMethod, Object params[])
{
string rawData = http.request(self.getRequestURL(apiMethod), httpMethod.toString(), http.buildQuery(params))
ApiResponse<T> obj = json.unserialize<ApiResponse<T>>(rawData);
if(obj.error != null)
{
throw ApiErrorException();
}
return obj.object;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment