public async Task OnResourceExecutionAsync(ResourceExecutingContext context, ResourceExecutionDelegate next) { var supported = ApiVersion.GetSupported(); try { if (!context.HttpContext.Request.Headers.ContainsKey(ApiHeaders.XExperienceApiVersion)) { throw new Exception($"Missing '{ApiHeaders.XExperienceApiVersion}' header."); } string requestVersion = context.HttpContext.Request.Headers[ApiHeaders.XExperienceApiVersion]; if (string.IsNullOrEmpty(requestVersion)) { throw new Exception($"'{ApiHeaders.XExperienceApiVersion}' header or it's null or empty."); } try { ApiVersion version = requestVersion; } catch (Exception) { throw new Exception($"'{ApiHeaders.XExperienceApiVersion}' header is '{requestVersion}' which is not supported."); } await next(); } catch (Exception ex) { context.HttpContext.Response.Headers.Add(ApiHeaders.XExperienceApiVersion, ApiVersion.GetLatest().ToString()); context.Result = new BadRequestObjectResult(ex.Message + " Supported Versions are: " + string.Join(", ", supported.Select(x => x.Key))); } }
public override void OnActionExecuting(HttpActionContext context) { var supported = ApiVersion.GetSupported(); try { if (!context.Request.Headers.Contains(ApiHeaders.XExperienceApiVersion)) { throw new Exception($"Missing '{ApiHeaders.XExperienceApiVersion}' header."); } IEnumerable <string> headerValues = context.Request.Headers.GetValues(ApiHeaders.XExperienceApiVersion); string requestVersion = headerValues.FirstOrDefault(); if (string.IsNullOrEmpty(requestVersion)) { throw new Exception($"'{ApiHeaders.XExperienceApiVersion}' header or it's null or empty."); } try { ApiVersion version = requestVersion; } catch (Exception) { throw new Exception($"'{ApiHeaders.XExperienceApiVersion}' header is '{requestVersion}' which is not supported."); } } catch (Exception ex) { var response = context.Request.CreateResponse(System.Net.HttpStatusCode.BadRequest, ex.Message + " Supported Versions are: " + string.Join(", ", supported.Select(x => x.Key))); context.Response = response; context.Response.Headers.Add(ApiHeaders.XExperienceApiVersion, ApiVersion.GetLatest().ToString()); } }
public Task <About> Handle(GetAboutQuery request, CancellationToken cancellationToken) { var about = new About() { Version = ApiVersion.GetSupported().Select(x => x.Key) }; return(Task.FromResult(about)); }
public Task <About> GetAbout(CancellationToken cancellationToken = default) { var about = new About() { Version = ApiVersion.GetSupported().Select(x => x.Key) }; return(Task.FromResult(about)); }
About() { Version = ApiVersion.GetSupported().Select(x => x.Key); Extension = new ExtensionsDictionary(); }