Cryptocurrency applications require real-time price data to display market values such as Bitcoin, Ethereum, and other digital assets. Many developers previously used the CoinDesk API, but it may sometimes fail due to DNS or service issues. A reliable alternative is the CoinGecko API, which provides free cryptocurrency price data without requiring authentication or an API key.
This article explains the concept of APIs, demonstrates how to consume a real-time cryptocurrency API, and provides complete backend and frontend code using ASP.NET Web API and JavaScript.
Understanding the API Concept
An API (Application Programming Interface) is a bridge that allows one software application to communicate with another. Instead of storing cryptocurrency prices locally, applications request the latest data from a remote server that maintains up-to-date market information.
In this example, the application sends an HTTP request to a public API. The API returns a JSON response containing the latest cryptocurrency price.
The workflow is simple:
User opens the webpage
Frontend sends request to ASP.NET API
ASP.NET API calls the CoinGecko API
CoinGecko returns the latest Bitcoin price
Backend returns the result to the frontend
Frontend displays the price
Recommended Free Crypto API
CoinGecko provides a free and reliable API endpoint.
API Endpoint
https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd
Sample JSON Response
{
"bitcoin": {
"usd": 68421
}
}
This response shows that the current Bitcoin price is 68421 USD.
Backend Implementation Using ASP.NET Web API
First create a Web API controller that will fetch cryptocurrency prices from CoinGecko.
CryptoController.cs
using System;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;
namespace CryptoAPI.Controllers
{
public class CryptoController : ApiController
{
[HttpGet]
[Route("api/crypto/bitcoin")]
public async Task<IHttpActionResult> GetBitcoinPrice()
{
string url = "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd";
using (HttpClient client = new HttpClient())
{
HttpResponseMessage response = await client.GetAsync(url);
if (!response.IsSuccessStatusCode)
{
return BadRequest("Unable to fetch crypto data");
}
string result = await response.Content.ReadAsStringAsync();
return Ok(result);
}
}
}
}

Join the conversation! Your thoughts help the community grow.