Generate your own QR Codes with a minimal API
This is going to be a short but important post.
QR Codes are used everywhere but oddly enough explaining how are generated is not well known.
QR Codes are made up of modules; a module stores data in rows and columns. Usually, QR codes are version 2 with 25 rows and 25 columns, and the data can be encoded in numeric, alphanumeric, binary or kanji which are stored in sections defined by bits.
You can learn more from:

We will be using the QRCoder NuGet library.
And the sample code will be at...
As promised, this will be short because we will be using minimal APIs. I love this approach and it is simpler to follow.
using QRCoder;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
var app = builder.Build();
app.UseHttpsRedirection();
//minimal api
app.MapGet("/", (HttpRequest request) =>
{
//get the query string
var qrCodeQuery = request.Query["content"];
var qrContent = string.Empty;
if (qrCodeQuery.Count > 0)
qrContent = qrCodeQuery.FirstOrDefault("No Content for QR Code");
//generate code
byte[] qrCodeImage;
using (QRCodeGenerator qrGenerator = new())
using (QRCodeData qrCodeData = qrGenerator.CreateQrCode(string.IsNullOrEmpty(qrContent) ? "https://darthseldon.net" : qrContent, QRCodeGenerator.ECCLevel.Q))
using (PngByteQRCode qrCode = new(qrCodeData))
{
qrCodeImage = qrCode.GetGraphic(20);
}
//return as image
var mimeType = "image/png";
return Results.File(qrCodeImage, contentType: mimeType);
});
app.Run();
Simple right?, we create the app, map the route and run the application.
In the mapping we extract the query string for the content parameter, generate the QR Code and then returning it as a PNG file.
I used Postman to test the URL and view the PNG.

This particular QR code will link to my main page of my blog, but QR codes are not only for links to web pages.
How about sharing a WIFI SSID and password; you can use...
WIFI:S:MySSID;T:WPA;P:MyPassW0rd;;
However, since we are using QRCoder library, the process is simplified by the payload generator class.
PayloadGenerator.WiFi wifiPayload = new PayloadGenerator.WiFi("MySSID", "MyPassW0rd", PayloadGenerator.WiFi.Authentication.WPA);
QRCodeData qrCodeData = qrGenerator.CreateQrCode(wifiPayload.ToString(), QRCodeGenerator.ECCLevel.Q);
QRCodeData qrCodeData = qrGenerator.CreateQrCode(wifiPayload, QRCodeGenerator.ECCLevel.Q);
You can generate
- Contact data
- WhatsApp Message
- Calendar Event
- SMS
- Many more
One more thing, in the C# solution, we are using the endpoint explorer.

You can add http files and create requests for your API, this is a quick way to test, however it is limited in its functionality.
I use it when I need to do continuous testing with hot reloading, once I have my APIs up and running, I switch to Postman.
Happy coding!!!