Pass multiple parameters in a POST API without using a DTO class in .Net Core MVC

后端 未结 5 1192
旧巷少年郎
旧巷少年郎 2021-02-15 16:53

I have an action on my web project which calls to an API

    [HttpPost]
    public async Task ExpireSurvey(int id)
    {
        var token =         


        
5条回答
  •  耶瑟儿~
    2021-02-15 17:00

    I think it would be helpful to recognize that ASP.NET Core is REST-based and REST fundamentally deals with the concept of resources. While not an unbreakable rule, the general idea is that you should have what you're calling DTOs here. In other words, you're not posting distinct and unrelated bits of data, but an object that represents something.

    This becomes increasingly important if you start mixing in things like Swagger to generate documentation for your API. The objects you create become part of that documentation, giving consumers of your API a template for follow in the development of their apps.

    Long and short, I'd say embrace the concept of resources/objects/DTOs/whatever. Model the data your API works with. It will help both you as a developer of the API and any consumers of your API.

提交回复
热议问题