
Introduction
APIs are everywhere in software development. Every time you use a mobile app, a website, or even smart devices, APIs help different systems communicate. In .NET Core, APIs let you create web services that send and receive data. This is especially useful in real-world applications like:
Employee management portals
Job boards
Flight booking systems
In this article, we will
Understand what an API is
Learn about endpoints
Create a simple API in .NET Core
See a real-life developer example
We will keep it simple and beginner-friendly, with clear explanations and code comments.
What is an API?
API stands for Application Programming Interface.
It helps two applications talk to each other — for example, your frontend app (React, Angular) and backend (database, server logic).
Think of it like a restaurant
You (frontend) tell the waiter (API) what you want.
The waiter (API) takes the order to the kitchen (backend).
The kitchen prepares the food (data).
The waiter brings it back to you.
Developer Example
Imagine a job portal. The frontend React app needs the list of jobs from the backend. The API delivers the data to display it on the web page — just like the waiter bringing your food.
What is an API Endpoint?
An endpoint is a specific URL where your API provides a service. It’s like a doorway through which the client (frontend) can ask the server (backend) for information or send data. Each endpoint usually performs a single action, such as retrieving a list of developers, fetching details of one developer, or adding a new developer.
Example
GET /api/developer => get all developers
GET /api/developer/1 => get developer with ID 1
POST /api/developer => add a new developerDeveloper Scenario
In a job portal, endpoints like GET /api/jobs or POST /api/jobs allow the frontend to show all jobs or add a new job posting. Without endpoints, the frontend and backend cannot communicate in a structured way.
Developer Example: Real-World Job Portal
Imagine you are building a job portal where users can browse and apply for jobs. Each action in the portal - like fetching jobs, adding a new job, or viewing job details - is handled by a specific endpoint in your API.
Example Endpoints
GET /api/jobs => Fetch all available jobs
POST /api/jobs => Add a new job posting
GET /api/jobs/123 => Fetch details of a specific job (ID = 123)How it works
GET /api/jobs
The frontend (React or Angular app) calls this endpoint to get a list of all jobs.
The API retrieves the jobs from the backend (database or storage) and sends them to the frontend.
Users see all the jobs listed in the portal.
POST /api/jobs
When an HR manager adds a new job, the frontend sends the job details to this endpoint.
The API saves the job in the backend and confirms success.
The new job now appears in the portal automatically.
GET /api/jobs/123
When a user clicks on a specific job to view details, this endpoint fetches only that job’s information.
The API returns the data, and the frontend displays it accurately to the user.
Why this matters:
Endpoints like these simplify communication between the frontend and backend. Each endpoint performs a single action, making your code clean, organized, and easy to maintain.
Create a Simple Web API in .NET Core
We’ll use .NET 6 or later.
Step 1. Create a New Project
In Visual Studio:
File => New => Project => ASP .NET Core Web API => Next => Create
You’ll see a default controller WeatherForecastController.cs. We will create our own DeveloperController.
Create Developer Controller with Comments
using Microsoft.AspNetCore.Mvc;
namespace MyFirstApi.Controllers
{
// This attribute tells .NET Core that this class is an API controller
[ApiController]
// Base route for this controller: api/developer
[Route("api/[controller]")]
public class DeveloperController : ControllerBase
{
// Static list to store developer names (temporary in-memory storage)
private static List<string> developers = new List<string> { "Rudra", "Abhinav", "Sham" };
// GET: api/developer
// Returns all developers in the list
[HttpGet]
public IActionResult GetAllDevelopers()
{
return Ok(developers); // 200 OK with the list of developers
}
// GET: api/developer/{id}
// Returns a developer by index (id)
[HttpGet("{id}")]
public IActionResult GetDeveloperById(int id)
{
// Check if id is valid
if (id < 0 || id >= developers.Count)
return NotFound("Developer not found"); // 404 if invalid
return Ok(developers[id]); // 200 OK with developer name
}
// POST: api/developer
// Adds a new developer to the list
[HttpPost]
public IActionResult AddDeveloper([FromBody] string name)
{
developers.Add(name); // Add new developer
return Ok($"Developer '{name}' added successfully!"); // Confirm success
}
}
}
Join the conversation! Your thoughts help the community grow.