Sometime I allow to create/update the status of IoT devices using the raw data. It means that the client can read the device device state as an array of bytes and send that data via API. The data parsed by the server and send back as a regular DTO.
For create I might introduce the following CreateStatusFromRawData method:
[HttpGet("{id}/status")]
[ProducesResponseType(200, Type = typeof(DeviceStatus))]
[ProducesResponseType(404)]
public async Task<IActionResult> GetStatus(Guid id)
{
// gets the device status
}
[HttpPost("{id}/status/rawdata")]
[ProducesResponseType(201, Type = typeof(DeviceStatus))]
[ProducesResponseType(404)]
public async Task<IActionResult> CreateStatusFromRawData(Guid id, [FromBody]byte[] rawdata)
{
// some parsing logic
return CreatedAtAction(nameof(GetStatus), new {id})
}
I would like to make the same for update operation:
[HttpPut("{id}/status/rawdata")]
[ProducesResponseType(200, Type = typeof(DeviceStatus))]
[ProducesResponseType(404)]
public async Task<IActionResult> UpdateStatusFromRawData(Guid id, [FromBody]byte[] rawdata)
{
// some parsing logic
return **UpdatedAtAction**(nameof(GetStatus), new {id})
}
How might UpdatedAtAction method implementation look like? So I want actually 3 things:
- Return status 200
- Get back updated status DTO
- Provide correct location header for getting status later via GET method