The two code snippets below show how to send a basic GET request to the Yay.com API using C# and PHP, the C# snippet has been tested using .NET Core and will work across all supported .NET platforms
C# Example
var dict = new Dictionary<string, string> {
{"X-Auth-Reseller", "reseller"},
{"X-Auth-User", "user"},
{"X-Auth-Password", "password"}
};
var client = new HttpClient {
BaseAddress = new Uri("https://api.yay.com/authenticated"),
DefaultRequestHeaders = {
UserAgent = {
new ProductInfoHeaderValue("ApiExample", "1.0")
}
}
};
foreach (var key in dict.Keys) {
client.DefaultRequestHeaders.Add(key, dict[key]);
}
var response = client.GetAsync("").Result;
if (!response.IsSuccessStatusCode) return;
var jsonResponse = response.Content.ReadAsStringAsync().Result;
PHP Example
The example below uses the Httpful library for ease of integration
// We use the httpful library for ease
include('httpful.phar');
try {
$response = \Httpful\Request::get('https://api.yay.com/authenticated')
->addHeaders(
array(
'X-Auth-Reseller' => 'reseller',
'X-Auth-User' => 'user',
'X-Auth-Password' => 'password'
)
)
->send();
printf($response->body);
} catch (\Httpful\Exception\ConnectionErrorException $e) {
printf($e);
}