Skip to content

Instantly share code, notes, and snippets.

@KevinMcDonnell-BC
Last active January 9, 2021 04:06
Show Gist options
  • Select an option

  • Save KevinMcDonnell-BC/641e93d284183f468558c7170a1112e4 to your computer and use it in GitHub Desktop.

Select an option

Save KevinMcDonnell-BC/641e93d284183f468558c7170a1112e4 to your computer and use it in GitHub Desktop.
BCServerlessDemo DataAndFunctions API
// from https://github.com/BallardChalmers/BCServerlessDemo.DataAndFunctions/blob/master/BCServerless.DataAndFunctions.Functions/Api/JourneysApi.cs
public async Task<HttpResponseMessage> Post(HttpRequestMessage req, TraceWriter log)
{
var payload = await req.Content.ReadAsAsync<Journey>();
var item = await _JourneyService.CreateAsync(payload, req);
return req.CreateResponse(HttpStatusCode.Created, item);
}
// from https://github.com/BallardChalmers/BCServerlessDemo.DataAndFunctions/blob/master/BCServerless.DataAndFunctions.Functions/Api/JourneysApi.cs
public async Task<HttpResponseMessage> Get(HttpRequestMessage req, TraceWriter log)
{
string idString = req.GetQueryNameValuePairs().Where(w => w.Key == "id").FirstOrDefault().Value;
if (string.IsNullOrWhiteSpace(idString))
{
var results = await _searchApi.Search<Journey, Journey>(req, log);
return req.CreateResponse(HttpStatusCode.OK, results);
}
var Journey = await _JourneyService.Get(idString);
if (Journey == null)
{
return req.CreateResponse(HttpStatusCode.NotFound);
}
return req.CreateResponse(HttpStatusCode.OK, Journey);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment