1

Below is my endpoint

// D - Delete
[HttpPost,HttpDelete]
[ProducesResponseType(204)]
[ProducesResponseType(400)]
public async Task<IActionResult> Delete([FromBody](int eventId, int personId, DateTime purchaseDate) reqTO)
{
   if (reqTO.eventId > 0 && reqTO.personId > 0 && reqTO.purchaseDate!= null)
   {
      var (flag, msg) = await _someRepository.Delete(reqTO.eventId, reqTO.personId, reqTO.purchaseDate);
      if (flag)
      {
         //204
         return CreateResponse<(int eventId, int personId, DateTime purchaseDate)>("Entry removed successfully", HttpStatusCode.NoContent, reqTO);
      }
      else
      {
            //TO DO
      }
   }
   else
   {
      return BadRequest();
   }
}

Now when I am calling this Endpoint from the postman with the below request payload

{
"eventId": 1,
"personId": 3,
"purchaseDate": "2019-01-04T18:25:43.511Z"
}

The Endpoint is hit, but the values assigned in the request payload are default values like eventId =0 ,personId =0 & purchaseDate = {01-01-0001 00:00:00}.

NOTE: I don't want to create any DTO.

How do I map ReqPayload to Named Tuple??

Kgn-web
  • 7,047
  • 24
  • 95
  • 161

1 Answers1

1

[HttpDelete] will ignore the request body so you are getting default values.

Use FromUri and pass values in parameter.

Or use [HttpPut] or [HttpPost] if you want to pass in request body.

Check this question hopefully it will be helpful. Is an entity body allowed for an HTTP DELETE request?

Karan
  • 12,059
  • 3
  • 24
  • 40