Using Postman to test HTTPPatch in .Net Core API, [FromBody] JsonPatchDocument<TEntity> patchEntity is null
-
[HttpPatch("{id:int}")]
public async TaskUpdatePartialAsync(int id, [FromBody] JsonPatchDocument patchEntity)
{
var entity = await _service.ReadAsync(id, false);
if (entity == null)
return NotFound();
try
{
patchEntity.ApplyTo(entity, ModelState);
}
catch(Exception ex)
{return Ok(ex.Message); } entity = await \_service.UpdateAsync(id, entity); return Ok(entity); }
When accessing this in PostMan, the return is an error, patchEntity has one Operation with all values being null. Any ideas?
-
[HttpPatch("{id:int}")]
public async TaskUpdatePartialAsync(int id, [FromBody] JsonPatchDocument patchEntity)
{
var entity = await _service.ReadAsync(id, false);
if (entity == null)
return NotFound();
try
{
patchEntity.ApplyTo(entity, ModelState);
}
catch(Exception ex)
{return Ok(ex.Message); } entity = await \_service.UpdateAsync(id, entity); return Ok(entity); }
When accessing this in PostMan, the return is an error, patchEntity has one Operation with all values being null. Any ideas?
thewizardoftn wrote:
the return is an error
Are we supposed to guess what the error is?
thewizardoftn wrote:
return Ok(ex.Message);
Returning an "OK" response for an exception seems like a particularly bad idea.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
[HttpPatch("{id:int}")]
public async TaskUpdatePartialAsync(int id, [FromBody] JsonPatchDocument patchEntity)
{
var entity = await _service.ReadAsync(id, false);
if (entity == null)
return NotFound();
try
{
patchEntity.ApplyTo(entity, ModelState);
}
catch(Exception ex)
{return Ok(ex.Message); } entity = await \_service.UpdateAsync(id, entity); return Ok(entity); }
When accessing this in PostMan, the return is an error, patchEntity has one Operation with all values being null. Any ideas?
You didn't check if
patchEntity
was null before dereferencing it."Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed." - G.K. Chesterton