What is API, REST principles, tools like Postman
Here’s a concise and beginner-friendly [Link] study material on Web API, REST principles, and
tools like Postman, perfect for understanding API development and testing in [Link] Core.
[Link] Core Study Material: API, REST, and Postman
1. What is an API?
API (Application Programming Interface)
• A software intermediary that allows two applications to communicate.
• In [Link] Core, an API allows your backend to expose data and functionality via HTTP
endpoints (like GET, POST, PUT, DELETE) to clients (like browsers, mobile apps, or Postman).
2. What is a Web API in [Link] Core?
• A Web API is a controller that handles HTTP requests and returns data (usually JSON)
instead of HTML views.
• It is built using [ApiController] attribute and follows RESTful principles.
Example:
[ApiController]
[Route("api/[controller]")]
public class ProductsController : ControllerBase
{
[HttpGet]
public IActionResult GetProducts()
{
var products = new List<string> { "Pen", "Notebook", "Eraser" };
return Ok(products);
}
}
3. REST (Representational State Transfer) Principles
REST is an architectural style that defines guidelines for creating scalable APIs. The key principles:
Concept Description
Stateless Each API call contains all the information the server needs (no session info).
Client-Server Frontend and backend are separated.
Cacheable Responses can be cached for performance.
Uniform Resources are accessed via standard HTTP methods (GET, POST, etc.).
Interface
Resource-based Use nouns in URLs, like /api/products/1 not verbs like /api/getProduct.
Layered System Multiple layers (authentication, logging, etc.) can exist between client &
server.
HTTP Method to CRUD Mapping:
HTTP Method Action Example Endpoint
GET Read /api/products
POST Create /api/products
PUT Update /api/products/5
DELETE Delete /api/products/5
4. Creating a Simple API in [Link] Core
Step-by-Step:
1. Create [Link] Core Web API project in Visual Studio or CLI:
2. dotnet new webapi -n MyApiProject
What is API, REST principles, tools like Postman
3. A default WeatherForecastController is generated as an example.
4. Add your own controller:
5. dotnet add package [Link]
6. Add model and controller.
5. Testing API with Postman
What is Postman?
• A powerful API testing tool used to send HTTP requests to your API and view responses.
Common Postman Actions:
Task Action in Postman
Send GET request Choose GET method, enter URL, click Send
Send POST request Choose POST, go to Body tab → raw → JSON
View response Bottom panel shows status code & JSON
Save collection Save grouped requests for reuse
Example: POST in Postman
1. URL: [Link]
2. Method: POST
3. Body → raw → JSON:
{
"id": 1,
"name": "Notebook"
}
4. Click "Send".
6. API Response Format
Typical JSON Response from [Link] Core:
[
{
"id": 1,
"name": "Pen"
},
{
"id": 2,
"name": "Notebook"
}
]
7. Tools Besides Postman
Tool Use Case
Swagger (Swashbuckle) Auto-generate API UI and test endpoints in browser
Insomnia Lightweight Postman alternative
Fiddler Inspect and debug HTTP traffic