.NET

C#, dotNet Core, ASP.NET, Entity Framework, testing, architecture, and everything .NET developers need.

Integrating with the ChatGPT API

Consume OpenAI APIs from your C# app

You can call the OpenAI (ChatGPT) API using HttpClient in C#. πŸ”‘ Get Your API Key Sign up at OpenAI and create a key. πŸš€ Sample POST Request 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20...

Test Organization and Naming Conventions

How to keep your tests tidy and clear

Good test organization makes it easy to find, run, and understand your tests. πŸ“‚ File and Folder Structure Put tests in a separate project or folder (e.g. MyApp.Tests). Mirror your code struc...

JSON Serialization and Deserialization

Convert C# objects to JSON and back

Modern APIs use JSON for data exchange. Here’s how to work with JSON in C#. πŸ”„ Serialize (Object β†’ JSON) 1 2 3 4 5 using System.Text.Json; var user = new User { Name = "Alice", Age = 30 }; string...

Testing with xUnit and NUnit

Popular testing frameworks for .NET

Automated tests help keep your code working as you make changes. The two most popular .NET testing libraries are xUnit and NUnit. πŸ§ͺ xUnit Built-in support with .NET CLI (dotnet new xunit) Te...

Unit Testing Basics

Test your code automatically

Unit tests check that small parts of your code work correctly automatically. πŸ§ͺ Why Test? Catch bugs early Refactor safely Prove your code works πŸ—οΈ Create a Test Project In terminal, ...

Using HttpClient for API Calls

Make HTTP requests in C#

HttpClient is the main way to call REST APIs from C#. πŸš€ Basic Usage 1 2 3 4 5 6 7 using System.Net.Http; using System.Threading.Tasks; var client = new HttpClient(); HttpResponseMessage response...

Async Best Practices

Write safe and efficient async code

Async is powerful, but there are some rules for writing safe, efficient code. βœ… Do Use async and await for slow operations (file/network). Always await async methods, don’t ignore the result...

Creating and Consuming REST APIs

API basics with ASP.NET Core and C# clients

REST APIs let applications communicate over HTTP. In .NET, you can both build APIs (servers) and consume them (clients). πŸ› οΈ Creating a REST API (ASP.NET Core) Create a project: 1 2 dotnet ...

Building RESTful APIs with C#

Your first web API with ASP.NET Core

ASP.NET Core makes building RESTful web APIs easy! πŸš€ Getting Started Create a new project: 1 2 dotnet new webapi -n MyApi cd MyApi Run your API: 1 dotnet run Visit h...

Handling Async Errors

Catching exceptions in asynchronous code

Async methods can throw exceptions, just like normal ones. Handle them with try/catch! πŸ›‘ Catching Exceptions in Async Code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 async Task FailAsync() { a...