REST API with ASP.NET 7

ZIN MIN
2 min readApr 7, 2023

--

Creating a REST API with ASP.NET 7 is as easy as eating a banana. But adhering to the standard URI naming convention for REST APIs can be a challenge for developers.

Because I got numerous upvote and notification from my Stack Overflow answer which I posted in 2018, addressing this issue.

https://stackoverflow.com/questions/35788911/500-error-when-setting-up-swagger-in-asp-net-core-mvc-6-app/52813518#52813518

Since then, Swagger is most popular tool to design the API and is already integrated into the Microsoft ASP.NET API project template, leading many developers to use Swagger and face issues with URI naming conventions. Swagger will throw an error if two URIs are ambiguous.

In the REST API standard URI naming convention, all URLs must follow a plural object or noun pattern. Method verbs are not allowed, and HTTP verbs are used to differentiate the URLs. The following HTTP verbs are useful for CRUD database APIs:

HttpGet

Retrieves something from the server. This is a read-only method.

HttpPost

Creates a new resource at the specified URI. This can be used to create a record for database CRUD functions.

HttpPut

Suitable for creating or updating the resource at the specified URI. For example, updating the record or changing the record status for database CRUD functions.

HttpPatch

Used for partial updates to a record, such as a soft delete status change of a record.

HttpDelete

Deletes the record from database.

From: Web API design best practices — Azure Architecture Center | Microsoft Learn

Here are some helpful articles I’ve read on the topic:

--

--