Skip to content

Instantly share code, notes, and snippets.

@dcomartin

dcomartin/vin.cs Secret

Created April 15, 2026 12:49
Show Gist options
  • Select an option

  • Save dcomartin/dec78c54c0e38e9a67fe7a425597e6c8 to your computer and use it in GitHub Desktop.

Select an option

Save dcomartin/dec78c54c0e38e9a67fe7a425597e6c8 to your computer and use it in GitHub Desktop.
public interface IVinDecoderService
{
Task<VinDecoderResult> Lookup(string vin, CancellationToken cancellationToken = default);
}
public class VinDecoderService : IVinDecoderService
{
private readonly HttpClient _httpClient;
public VinDecoderService(HttpClient httpClient)
{
_httpClient = httpClient;
}
public async Task<VinDecoderResult> Lookup(string vin, CancellationToken cancellationToken = default)
{
var response = await _httpClient.SendAsync(new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = new Uri($"https://api.vindecoder.com/{vin}/specs")
}, cancellationToken);
if (!response.IsSuccessStatusCode)
{
throw new Exception("Error calling API to decode VIN");
}
var result = await response.Content.ReadFromJsonAsync<VinDecoderResult>(cancellationToken: cancellationToken);
return result ?? throw new Exception("Error calling API to decode VIN");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment