Skip to main content

66 posts tagged with "Web API"

Building HTTP Web APIs That Other Apps Call

View All Tags

Fixed: "Duplicate entry for key 'order_lines.IX_order_lines_OrderId_ProductId'" When a List Repeats a Product in a Minimal API

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

A request that listed the same product twice in one order got a 500, and the log had MySQL's Duplicate entry '2-9' for key 'order_lines.IX_order_lines_OrderId_ProductId'. The database was right to refuse. But a mistake in the request should be a 400, and it shouldn't take stock and open a transaction to find out.

How to Connect a .NET C# Web API to a MySQL Database — Part 3: Read and Write MySQL Data with EF Core

· 71 min read
Jagdish Kumawat
Founder @ Dewiride

Part 2 created the tables, and they're still empty. In this part the API starts using them: you'll insert, read, change and delete rows through real endpoints, and read the SQL that EF Core sends to MySQL for every one of them. You'll also turn MySQL's refusals, such as a duplicate name, into clear HTTP answers, and stop two people from silently overwriting each other's changes.

How to Set Different Log Levels per Environment in appsettings.json

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

On your machine you want to see every SQL statement. In Production you don't: it's noise, and it costs money to store. ASP.NET Core reads appsettings.json, then the file for the current environment on top of it, so one setting in each gives you both. This guide does that for EF Core's SQL log, and checks it in both environments.

How to Bind Query String Parameters with AsParameters in a Minimal API

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

A list endpoint collects options: a search term, a category, a sort, a page. Six parameters on one method is hard to read, and passing them along is worse. [AsParameters] puts them in one record, filled from the query string as if each property were its own parameter. This guide uses it on a real product list, with the one detail ASP.NET Core 10 needs.