.webp)
Ubong Umoh
Ubong Umoh is a passionate software engineer who loves building clean, efficient, and impactful solutions. With a strong focus on backend development, APIs, and system design, he enjoys turning complex ideas into simple, scalable applications. When he’s not coding, he’s exploring new technologies, writing about software engineering, and helping others grow in tech.
Article by Gigson Expert
Have you ever opened an app and wondered how it magically pulls live information from somewhere — like when your weather app shows the temperature in real-time or your bank app updates your balance instantly?
That’s not magic. That’s APIs doing their thing behind the scenes.
APIs are the unsung heroes of modern software. They quietly connect everything — from your mobile apps to web platforms, payment gateways, and even IoT devices. In fact, if the internet were a city, APIs would be the roads, bridges, and tunnels linking it all together.
So in this post, let’s unpack what APIs really are, how they power everything on the web, and even look at a few C# code samples to bring it all to life.
What Is an API (in Plain English)?
Imagine you’re at a restaurant. You’re the customer, the kitchen is the system preparing your order, and the waiter is the API.
You don’t go into the kitchen to make your meal — you just tell the waiter what you want, and they deliver it to you.
That’s exactly how APIs work. They act as messengers between two systems. One system (the client) sends a request; the other system (the server) processes it and sends back a response.
In short:
An API defines how two systems can talk to each other safely and efficiently.
Every time you click “Pay with PayPal,” “Sign in with Google,” or “Check flight status,” an API call is happening somewhere in the background.
Why APIs Matter (and Why You Should Care)
We can’t really talk about modern software without APIs. They’ve become the backbone of digital communication. Here’s why:
1. Integration Made Easy
APIs make systems work together. Your favorite e-commerce site using Google Maps for delivery tracking? That’s an API in action.
2. Reusability
Instead of reinventing the wheel, you can leverage existing services — like using Termii’s API for SMS, or Paystack for payments.
3. Security
You don’t need to expose your internal code. APIs allow you to share only the specific data or functions you want others to access.
4. Scalability
You can expand functionality by simply plugging in new APIs. Think of them as Lego pieces — reusable, modular, and flexible.
Types of APIs You’ll Run Into
There are a few main types, but most developers deal with Web APIs. Here’s the breakdown:
For this article, we’ll focus on Web APIs, since they power most of what happens online.

REST, SOAP, and GraphQL — What’s the Difference?
REST (Representational State Transfer)
This is the most common style. It’s simple, lightweight, and uses HTTP verbs:
- GET → Retrieve data
- POST → Create new data
- PUT → Update existing data
- DELETE → Remove data
Example:
GET https://api.openweathermap.org/data/2.5/weather?q=LagosSOAP (Simple Object Access Protocol)
SOAP is older and more rigid. It uses XML and is common in enterprise systems.
GraphQL
A newer technology from Facebook. It lets clients specify exactly what data they need — no more, no less.
Let’s Use a Real API in C#
Enough theory — let’s get our hands dirty with some code.
We’ll use C# and HttpClient to call real-world APIs.
Example 1: Fetch a Random Joke
using System;
using System.Net.Http;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
using HttpClient client = new HttpClient();
string url = "https://official-joke-api.appspot.com/random_joke";
HttpResponseMessage response = await client.GetAsync(url);
if (response.IsSuccessStatusCode)
{
string json = await response.Content.ReadAsStringAsync();
Console.WriteLine("Joke of the day:");
Console.WriteLine(json);
}
else
{
Console.WriteLine("Error: " + response.StatusCode);
}
}
}What’s happening here:
- HttpClient sends a GET request.
- The API returns a JSON response.
- We print it out.
That’s literally all it takes to call an external service
Example 2: Getting Live Weather Data
Parsing JSON Responses in C#
In real-world projects, you’ll want to deserialize (convert) the API’s JSON response into C# objects. That’s where System.Text.Json comes in.
Let’s call a weather API for a specific city using OpenWeatherMap.
using System;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
class WeatherResponse
{
public MainInfo Main { get; set; }
}
class MainInfo
{
public double Temp { get; set; }
}
class WeatherApp
{
static async Task Main()
{
string apiKey = "your_api_key_here";
string city = "Lagos";
string url = $"https://api.openweathermap.org/data/2.5/weather?q={city}&appid={apiKey}&units=metric";
using HttpClient client = new HttpClient();
HttpResponseMessage response = await client.GetAsync(url);
if (response.IsSuccessStatusCode)
{
string result = await response.Content.ReadAsStringAsync();
// Deserialize JSON into a C# object
var weatherData = JsonSerializer.Deserialize<WeatherResponse>(result);
Console.WriteLine($"✅ Successfully fetched weather data!");
Console.WriteLine($"Temperature in {city}: {weatherData.Main.Temp}°C");
}
else
{
Console.WriteLine($"❌ Failed to fetch weather data. Status Code: {response.StatusCode}");
string error = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Error details: {error}");
}
}
}You’ll need to sign up for a free API key at openweathermap.org.Once you plug it in, you’ll get live temperature and weather data for any city in the world.
Example 3: Sending Data with POST
What if you want to send data instead of fetching it?
Here’s a simple example using a mock API:
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class PostExample
{
static async Task Main()
{
using (HttpClient client = new HttpClient())
{
var json = "{\"name\":\"Ubong\",\"email\":\"ubong@example.com\"}";
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PostAsync("https://jsonplaceholder.typicode.com/users", content);
string result = await response.Content.ReadAsStringAsync();
Console.WriteLine("Response:");
Console.WriteLine(result);
}
}
}What’s happening: We’re sending JSON data (a name and email) to a fake API endpoint.This mimics how real apps submit data — think “register user,” “place order,” or “create post.”
A Quick Word on API Security
Most APIs don’t just hand out data freely — they require authentication.
Here are some common methods:

To include a token in your C# request, simply add this line:
client.DefaultRequestHeaders.Add("Authorization", "Bearer your_api_token_here");Never hardcode your API keys in public repositories — use environment variables or configuration files to store sensitive data. Also be aware of rate limiting (restrictions on request frequency) and CORS (Cross-Origin Resource Sharing), which defines which domains can access your API.
Building Your Own API in C#
Want to go a step further? You can create your own API easily with ASP.NET Core.
Creating Your First Web API in C#
Open your terminal and run the following commands:
dotnet new webapi -n MyFirstApi
cd MyFirstApi
dotnet run
Now, add this controller:
using Microsoft.AspNetCore.Mvc;
[ApiController]
[Route("api/[controller]")]
public class HelloController : ControllerBase
{
[HttpGet]
public IActionResult Get()
{
return Ok(new { message = "Hello from my first API!" });
}
}
When you visit:
https://localhost:5001/api/hello
You’ll see this JSON response:
{
"message": "Hello from my first API!"
}Boom, your API is live.
APIs in Real Life
Once you start noticing APIs, you’ll see them everywhere:
- Bank apps fetching your balance
- E-commerce sites processing payments
- Ride-hailing apps tracking your driver’s location
- Social media apps showing friend suggestions
- Even your smart TV streams Netflix!
Everything that connects, syncs, or updates in real-time likely uses an API.
Best Practices When Working with APIs
Here are a few tips I’ve learned from experience:
- Always handle errors gracefully – network issues happen.
- Use async/await – it keeps your app responsive.
- Cache responses when possible.
- Secure your API keys – never commit them.
- Respect rate limits – don’t hammer someone’s API.
- Read the documentation – it’s your best friend.
Wrapping Up
APIs are the invisible threads weaving the modern web together.
They’re what allow your code to talk to the rest of the world — to fetch, post, and share data seamlessly.
Whether you’re building a weather app, a payment system, or your own startup idea, understanding APIs gives you superpowers.
So go ahead — make that first call, build that endpoint, and see the web come alive through your code.
FAQs
Can I use APIs without an internet connection?
Most web APIs require internet access, though local APIs (like OS-level APIs) can work offline.
Do I need to pay for all APIs?
Many APIs offer free tiers or limited use, but production-level access usually comes with a paid plan.
What’s the best way to test APIs?
Tools like Postman or cURL are great for testing and inspecting responses before coding.

.webp)




