1
私は2つの異なるAPIエンドポイントを持っています。両方のコントローラはApiController
を継承します。どちらも、単一オブジェクトを返します。それぞれのオブジェクトのフィールドは、DateTime
です。同じAPI内の異なるエンドポイントが異なる日付形式を返すのはなぜですか?
API 1:
public class ReadingProgressResponse
{
public DateTime DateTime { get; set; }
// and other properties
}
サンプル応答:
{
"dateTime": "2016-09-28T14:30:26"
}
API 2
Response1のように定義される[Route("OtherThings/{otherThingId:guid}/FirstThing", Name = "GetFirstThing")]
[HttpGet]
[ResponseType(typeof(Response1))]
public IHttpActionResult GetFirstThing(Guid otherThingId, [FromUri] DateTime? modifiedDate = null)
{
var things = GetThings(otherThingId, modifiedDate);
if (!things.Any())
{
return NotFound();
}
return Ok(new Response1(things.First()));
}
public class ScreenSessionResponse
{
public DateTime ExpirationTime { get; set; }
// and other fields
}
サンプル応答:API 1日の終わりに "Z" を有するが、API 2ないこと
{
"expirationTime": "2016-09-28T14:48:09Z"
}
注意Response2
のように定義される
[HttpGet]
[Route("{someId:guid}", Name = "SomeName")]
[ResponseType(typeof (Response2))]
public IHttpActionResult GetResponse2(Guid someId)
{
var data = GetSomeData(someId);
return Ok(new Response2(data));
}
そうです。
なぜですか?レスポンスのフォーマット方法を制御できますか?