Types of APIs Based on Accessibility: Explained with Simple Examples

Osama HaiDer
2 min readNov 18, 2024

--

APIs (Application Programming Interfaces) are tools that let different software systems talk to each other. They come in many types, depending on how they are accessed. Let’s explore the main types based on accessibility with easy-to-understand examples.

1. Open APIs (Public APIs)

Open APIs are available for anyone to use. Developers and users can access these APIs with very few restrictions. These are great for adding extra features to your application, like maps or weather updates.

Example

Imagine you are building a travel app in .NET. You can use the Google Maps API to show locations or directions.

var httpClient = new HttpClient();
var response = await httpClient.GetAsync("https://maps.googleapis.com/maps/api/geocode/json?address=NewYork&key=YOUR_API_KEY");
var data = await response.Content.ReadAsStringAsync();
Console.WriteLine(data);

This API helps you integrate maps into your app without building a map system from scratch.

2. Internal APIs (Private APIs)

Internal APIs are used within an organization. They allow different systems or teams to communicate securely. For example, a company might have an API to manage its users and employees. These APIs are not shared with the outside world.

Example

If your .NET application has a private API for fetching employee details:

[HttpGet("employee/{id}")]
public IActionResult GetEmployeeDetails(int id)
{
// Fetch details from internal systems
var employee = _employeeService.GetEmployeeById(id);
return Ok(employee);
}

This API is only accessible by your company’s other internal apps or tools.

3. Partner APIs

Partner APIs are shared with specific businesses or clients. They are not open to the public but allow secure communication between trusted parties. For instance, an e-commerce platform might use a payment gateway API to process payments.

Example

Let’s say you’re integrating Stripe’s payment gateway in your .NET app:

var paymentRequest = new
{
amount = 5000,
currency = "usd",
source = "tok_visa", // This comes from the front-end
description = "Test Payment"
};

var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer YOUR_API_KEY");
var response = await httpClient.PostAsJsonAsync("https://api.stripe.com/v1/charges", paymentRequest);
var result = await response.Content.ReadAsStringAsync();
Console.WriteLine(result);

This Partner API ensures only your application can communicate securely with Stripe.

4. Composite APIs

Composite APIs combine multiple APIs into one, making it easier to fetch data from different sources in a single request. For example, a dashboard application might need user profile and purchase history data.

Example

In your .NET app, you can create a composite API that fetches data from two different services:

[HttpGet("user-dashboard/{userId}")]
public async Task<IActionResult> GetUserDashboard(string userId)
{
var userDetails = await _userService.GetUserDetails(userId);
var purchaseHistory = await _purchaseService.GetPurchaseHistory(userId);

var dashboardData = new
{
UserDetails = userDetails,
PurchaseHistory = purchaseHistory
};

return Ok(dashboardData);
}

This way, instead of making two separate API calls, the client gets all the information in one response.

Final Thoughts

Each type of API has its own purpose and use case. Whether it’s open APIs to add new features, internal APIs for secure in-house operations, partner APIs to work with other businesses, or composite APIs to simplify data access, they all help make applications more powerful and user-friendly.

By understanding these API types and using them effectively, you can build better applications in .NET or any other platform.

--

--

Osama HaiDer
Osama HaiDer

Written by Osama HaiDer

SSE at TEO International | .Net | Azure | AWS | Web APIs | C#

No responses yet