Below are some typical examples of code for common programming languages of how you could access the MIDAS API.
In the following examples the "
get_setting" API call is made in order to retrieve the current version of MIDAS
C# |
using(WebClient client = new WebClient())
{
System.Collections.Specialized.NameValueCollection reqparm = new System.Collections.Specialized.NameValueCollection();
parameters.Add("key", "your_api_key");
parameters.Add("action", "get_setting");
parameters.Add("setting", "version");
byte[] responsebytes = client.UploadValues("https://your_midas_url/api.pl", "POST", parameters);
string response = Encoding.UTF8.GetString(responsebytes);
}
|
Java |
HttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost("https://your_midas_url/api.pl");
List<NameValuePair> params = new ArrayList<NameValuePair>(3);
params.add(new BasicNameValuePair("key", "your_api_key"));
params.add(new BasicNameValuePair("action", "get_setting"));
params.add(new BasicNameValuePair("setting", "version"));
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
try {
// process response
} finally {
instream.close();
}
}
|
jQuery |
$.post("https://your_midas_url/api.pl", { key: "your_api_key", action: "get_setting", setting: "version" })
.done(function(response) {
alert("Response: " + response);
}, "JSON");
|
.NET |
using System;
using System.Collections.Specialized;
using System.Net;
public static class Http
{
public static byte[] Post(string uri, NameValueCollection pairs)
{
byte[] response = null;
using (WebClient client = new WebClient())
{
response = client.UploadValues(uri, pairs);
}
return response;
}
}
var response = Http.Post("https://your_midas_url/api.pl", new NameValueCollection() {
{ "key", "your_api_key" },
{ "action", "get_setting" },
{ "setting", "version" }
});
|
Perl |
use LWP::UserAgent;
my$ua = LWP::UserAgent->new(env_proxy => 0,keep_alive => 0,timeout => 30,agent =>'Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 5.0)');
my$request = $ua->post("https://your_midas_url/api.pl", [key => "your_api_key", action => "get_setting",setting=>"version"]);
if ($request->is_success) {
$response=$request->content;
}
|
PHP |
$parameters = "key=your_api_key&action=get_setting&setting=version";
$ch = curl_init("https://your_midas_url/api.pl");
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $parameters);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec( $ch );
|
Python |
import urllib
import urllib2
parameters = {'key' : 'your_api_key',
'action' : 'get_setting',
'setting' : 'version' }
data = urllib.urlencode(parameters)
req = urllib2.Request("https://your_midas_url/api.pl", data)
getresponse = urllib2.urlopen(req)
response = getresponse.read()
|
Ruby |
require "net/http"
require "uri"
uri = URI.parse("https://your_midas_url/api.pl")
response = Net::HTTP.post_form(uri, {"key" => "your_api_key", "action" => "get_setting", "setting" => "version"})
|