Ali Hamza Ansari

Ali Hamza Ansari

Meet Ali, a talented .NET developer from Pakistan. Besides blogging, Ali works for a range of international customers doing everything from C# to Azure.

77 posts •
Building AI features in .NET with Microsoft.Extensions.AI

Microsoft.Extensions.AI gives .NET one set of abstractions for talking to AI providers. This post builds a console chatbot with IChatClient, streaming responses and conversation history. It then adds typed, structured output and handles rate limits, so the demo holds up on a free-tier model. ...

MCP server vs REST API: When should you use each?

REST APIs serve applications whose developers already know the endpoints. MCP lets AI agents discover tools at runtime and ask for approval mid-task. This post compares caching, discovery, auth and context cost, and shows why most systems pair an MCP layer with their REST API. ...

What is tool calling in AI? Build a simple .NET example

LLMs understand language, but they can't query your database or call an API on their own. Tool calling closes that gap: the model names a function and its arguments, and your app runs it. This post walks through a flight booking example, shows a C# tool definition, and covers common use cases. ...

Why AI-Generated code still needs tests

AI tools turn ideas into working apps in minutes, but they don't know your business rules, architecture or security requirements. Generated code can look right and still hide gaps, so it needs tests and human review. This post covers where it falls short and how to use AI safely. ...

Memory-efficient JSON in .NET 10 web APIs with PipeReader

Deserializing a JSON payload with a million objects strains memory and the garbage collector. .NET 10 adds PipeReader support to System.Text.Json, letting the serializer read straight from a pipeline. This post benchmarks it against streams on execution time, allocations, and GC collections. ...

Designing APIs for AI agents: your API has a new user

AI agents are a new kind of API consumer: they call endpoints, retry requests, and chain multi-step workflows on their own. This post covers practical ASP.NET Core patterns for building agent-ready APIs, including DTOs, idempotency, pagination, machine-readable errors, auth, and llms.txt. ...

Swagger vs. Scalar: A comparison for ASP.NET Core developers

Swagger UI used to ship by default with ASP.NET Core API projects, but recent .NET versions replaced it with a bare OpenAPI document. This post compares Swagger and Scalar as documentation UIs, walks through setting up each one in .NET 10, and covers when to pick one over the other. ...

Using C# 14 to build "Smart records" for config & settings models

Traditional config classes let properties be mutated anywhere and accept invalid values with no warning. This article shows how to use C# 14's new extension-block syntax with records to build "smart records" - immutable, self-validating configuration models for cleaner, safer ASP.NET Core apps. ...

Getting started with RAG in ASP.NET Core

AI hype is everywhere, but where do you start with .NET? In this beginner-friendly post, we build a simple RAG pipeline in an ASP.NET Core Web API using keyword matching instead of embeddings, covering retrieve, augment, and generate end to end, with vector embeddings saved for a later post. ...