【发布时间】:2019-05-23 12:15:16
【问题描述】:
有时我允许使用原始数据创建/更新 IoT 设备的状态。这意味着客户端可以将设备设备状态作为字节数组读取,并通过 API 发送该数据。由服务器解析并作为常规 DTO 发送回来的数据。
对于创建,我可能会介绍以下CreateStatusFromRawData 方法:
[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})
}
我想对更新操作做同样的事情:
[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})
}
UpdateAtAction 方法的实现是什么样的?所以我实际上想要三件事:
- 返回状态 200
- 取回更新的状态 DTO
- 提供正确的位置标头,以便稍后通过 GET 方法获取状态
【问题讨论】:
标签: c# .net rest .net-core asp.net-core-webapi