To connect to a resource, you first authenticate with the server.
Topics on this page:
The connection and authentication is currently as simple as logging into the server and providing your username and password.
The following examples show:
http://myusername:mypassword@myhost/rundb/api/v1/experiment
curl --user mysername:mypassword
--header "Content-Type: application/json"
--location 'http://myhost/rundb/api/v1/experiment'
restful_lib
NOTE: restful_lib has not been updated in over 5 years and is considered deprecated.
from restful_lib import Connection
base_url = 'http://myhost/rundb/api/v1'
conn = Connection(base_url, username="myusername", password="mypassword")
httplib2
import httplib2
h = httplib2.Http()
h.add_credentials('myusername', 'mypassword')
requests (recommended)
import requests
resp = requests.get('http://myhost/rundb/api/v1?format=json', auth=('myusername', 'mypassword'))
<?php
$context = stream_context_create(array(
'http' => array(
'header' =>
"Authorization: Basic " . base64_encode("myusername:mypassword")
)
));
$url = "http://myhost/rundb/api/v1?format=json";
$feed = file_get_contents($url, false, $context);
?>
$.ajax({
url: "http://myusername:mypassword@myhost/rundb/api/v1/experiment",
dataType: 'jsonp',
success: handleResponse(json_results)
});