public static HttpResponseMessage Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "v1/subwayLines/{color}")] HttpRequestMessage req, string color, TraceWriter log) { // TODO: validate input // TODO: move serialization into service // TODO: enum for colors // TODO: consolidate with commuter rail? // TODO: OpenAPI Spec // TODO: functional tests // move auth error into functional tests var authError = AuthSvc.GetAuthenticationError(req); if (authError != null) { return(authError); } var colorCleaned = color.ToLower(); string directionCleaned = GetRequestParam <string>(req, "direction").ToLower(); DateTime timeOfTravel = GetRequestParam <DateTime>(req, "timeOfTravel"); bool? isWeekend = GetRequestParam <bool?>(req, "isWeekend"); var answer = BikeTheTSvc.BikesAllowedOnSubway(colorCleaned, directionCleaned, timeOfTravel, isWeekend); return(CreateResponse(colorCleaned, directionCleaned, timeOfTravel, isWeekend, answer)); }
public static HttpResponseMessage Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "v1/commuterRailTrains/{trainNum}")] HttpRequestMessage req, string trainNum, TraceWriter log) { var authError = AuthSvc.GetAuthenticationError(req); if (authError != null) { return(authError); } var bikesAllowed = BikeTheTSvc.BikesAllowedOnCommuterRailTrain(trainNum); var answer = new CommuterRailDto() { TrainNum = trainNum, BikesAllowed = bikesAllowed }; var jsonSerializerSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(JsonConvert.SerializeObject(answer, jsonSerializerSettings), Encoding.UTF8, "application/json") }); }