如何告诉 web api ApiExplorer 端点将 return 二进制数据(如 zip 文件)?
How to tell web api ApiExplorer that the endpoint will return binary data (like a zip file)?
对于端点 returning 模型,我们可以使用 ResponseTypeAttribute
来告诉帮助页面文档 return 数据的外观:
/// <summary>
/// returns the specified Foo.
/// </summary>
[ResponseType(typeof(FooModel))]
[HttpGet]
[Route("~/api/foos/{fooId}")]
public async Task<IHttpActionResult> GetFoo(int fooId)
{
...
}
这将成为 Api 帮助页面上的一个很好的条目,描述该端点的行为方式。
我想记录某个端点将 return 一个 application/zip 二进制流。我该怎么做?
好吧,如果您已经知道您的 api 端点将转到 return zip 文件,那么您可以将其硬编码为 application/octet-stream
。
content-type = "application/octet-stream"