API 的 POST 响应的符合标准的内容和格式是什么?

What is the standards-adherent content and format of an API's POST repsonse?

我是 运行 具有服务器端 Web 服务的 SPA。

那是我的行动:

public async Task<IActionResult> Post([FromBody]CreateSchoolclassCodeRequestDto dto)
{
    await service.CreateSchoolclassCodeAsync(dto);
    return result;
}

符合标准的结果数据会是什么样子?

什么 IActionResult 符合标准?

请附上解释答案的规范。

How will your result data look like?

Section 10 of RFC2616 states 成功的 POST 响应将包括 "an entity describing or containing the result of the action." 在您的情况下,响应可以包含服务器在收到 POST 时创建的实际结果。

And what concrete IActionResult would you use?

ASP.NET Core MVC 提供了五个可行的替代方案。您的示例没有说明选择哪个;所以这里有一些指导方针。

Section 9 of RFC2626 指定了对成功 POST 的三个规范响应,并声明我们应该选择最详细的可用响应。以下是从最详细到最不详细的三个以及它们的 ASP.NET 核心 MVC 实现。

201(已创建)响应。 如果您可以使用 URI 标识结果并且可以包含描述结果的实体,请使用此选项。 ASP.NET Core MVC 提供了三个等效的实现:

200(确定)响应。 如果您无法使用 URI 识别结果但可以包含一个实体来描述结果,请使用此选项。 ASP.NET Core MVC 提供了 OkObjectResult.

204(无内容)响应。 如果您无法使用 URI 识别结果并且无法包含描述结果的实体,请使用此选项。 ASP.NET Core MVC 提供了 NoContentResult.