VS attribute-based routing Conferencing-based routing is best practice for ASP.NET Core RESTful APIs

I am an experienced .NET developer, taking the first steps in .NET Core over the past few days, more specifically in creating a RESTful API using ASP.net Core.

I know that there are 2 possible routing options - Console Routing (traditional) and Attribute Based Routing (newer).

I read that the recommendation of the core ASP.net team is to use attribute-based routing for the API , rather than traditional conventional routing, which is more suitable for MVC applications.

I would really like to understand - Why ?

Attribute-based routing seems to make us write more code, ending up with the same behavior as regular routing.

+4
source share
1 answer

Both options are valid. Below are some suggestions on when to use them. Consider choosing traditional routes when:

  • You need a centralized configuration of all your routes.
  • You are using custom constraint objects.
  • You have an existing working application that you do not want to modify.

Consider choosing attribute routes when:

  • Do you want to save your routes along with an action code
  • .
  • (), , , , , asp.net.

, Attribute Routes, - , , . , .

+6

Source: https://habr.com/ru/post/1670842/


All Articles