Monday, February 13, 2017

When you want to make a async API endpoint and stub it out to just return canned data in the short term, what does the await part look like?

[HttpGet, Route("widgets/{customerId:long}")
public async Task<IHttpActionResult> GetWidgets(long customerId)
{
   List<OrderNumber> widgets = new List<OrderNumber>()
   {
      new Widget()
      {
         PartNumber = 4534,
         Name = "FlapTrapWackyWonk"
      },
      new Widget()
      {
         PartNumber = 346456346,
         Name = "GusGuffGunkGooey"
      }
   };
   return Json(widgets);
}

 
 

becomes...

[HttpGet, Route("widgets/{customerId:long}")
public async Task<IHttpActionResult> GetWidgets(long customerId)
{
   List<OrderNumber> widgets = new List<OrderNumber>()
   {
      new Widget()
      {
         PartNumber = 4534,
         Name = "FlapTrapWackyWonk"
      },
      new Widget()
      {
         PartNumber = 346456346,
         Name = "GusGuffGunkGooey"
      }
   };
   return Json(await Task.FromResult(widgets));
}

No comments:

Post a Comment