Horses and people › A jockey's record
A jockey's record
Find a jockey by name, then read the career record: rides, wins and strike rate.
// A jockey's record (a .NET 6 or later console app)
using System.Text.Json;
var http = new HttpClient { BaseAddress = new Uri("https://api.apihorseracing.com") };
http.DefaultRequestHeaders.Add("X-API-Key", Environment.GetEnvironmentVariable("AHR_KEY"));
async Task<JsonElement> Get(string path)
{
var res = await http.GetAsync(path);
var body = JsonDocument.Parse(await res.Content.ReadAsStringAsync()).RootElement;
if (!res.IsSuccessStatusCode)
throw new Exception(body.GetProperty("error").GetProperty("code").GetString());
return body.GetProperty("data");
}
var first = (await Get("/v1/jockeys/search?name=Townend"))[0];
var data = await Get("/v1/jockeys/" + first.GetProperty("jockey_id") + "");
Console.WriteLine("Jockey: " + data.GetProperty("name"));
Console.WriteLine("Rides: " + data.GetProperty("record").GetProperty("runs"));
Console.WriteLine("Wins: " + data.GetProperty("record").GetProperty("wins"));
Console.WriteLine("Win share: " + data.GetProperty("record").GetProperty("win_pct"));
What the reply holds
- record.runs
- Rides on file.
- record.wins
- Winners.
- record.win_pct
- Wins as a share of rides, 0 to 1.
When it says no
401no_key The key is missing or mistyped. Every sample reads it from AHR_KEY.403plan_needed Your plan does not reach this. The reply names the plan that does.429rate_limited Too fast. Wait the seconds in Retry-After, then try again.