May 2018
Intermediate to advanced
334 pages
7h 25m
English
The HTTP PUT verb is idempotent. This means that the first HTTP PUT request with a certain payload will impact the server and the resource. It will update the resource specified by ID. However, subsequent HTTP PUT requests with the same payload would result in the same response as the first one.
Consider the following example where we will update one product:
// PUT: api/Products/1[HttpPut("{id}")]public async Task<IActionResult> Put(int id, [FromBody]Product product) => (await _productService.UpdateProductAsync(id, product)) ? Ok() : StatusCode(500);
The [HttpPut] attribute is supplied with a template of {id} similar to what we had in [HttpGet]. In the case of PUT, it would get the ID from the URL and the Product object from the body ...