简体   繁体   中英

What's the difference between [HttpGet] and [HttpGet("{id}")]?

What are the differences between HTTPGET method and HTTPGET("{id}") method? What is the API method that is used to update table columns?

[HttpGet]
public IActionResult Get()
{
    return new JsonResult(users);
}

// GET api/values/5
[HttpGet("{id}")]
public IActionResult Get(string id)
{
    return new JsonResult(response);
}

You should take a look at Attribute Routing in Web API.

The first method is routing to a clean api:

/api/controller

The second specifies route value in the attribute and will be called via the following url:

/api/controller/5

The second one is normally used to update existing queries, as you specify specific value in the route whilst the first specifies nothing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM