Ejemplo n.º 1
0
 public static ParameterResolver <T> Query <T>(string name, T defaultValue)
 => ParameterResolver <T> .Create(
     Type.Query,
     (request, mappedParameters) =>
 {
     string?value;
     try
     {
         value = request.QueryParameters.ValuesOf(name) ![0];
Ejemplo n.º 2
0
 public static ParameterResolver <T> Body <T>(MediaTypeMapper mediaTypeMapper)
 => ParameterResolver <T> .Create(
     Type.Body,
     (request, mappedParameters) =>
 {
     var assumedBodyContentType = ContentMediaType.Json.ToString();
     var bodyMediaType          = request.HeaderValueOr(RequestHeader.ContentType, assumedBodyContentType);
     return(mediaTypeMapper.From <T>(request.Body?.ToString(), ContentMediaType.ParseFromDescriptor(bodyMediaType)));
 });
Ejemplo n.º 3
0
 public static ParameterResolver <T> Body <T>(MediaTypeMapper mediaTypeMapper)
 {
     return(typeof(T).IsAssignableFrom(typeof(RequestData)) ?
            (ParameterResolver <T>)(object) ParameterResolver <RequestData> .Create(Type.Body, (request, mappedParameters) =>
     {
         // This is a fall-back when content-type not provided for backwards compat for curl/cmd line users
         var bodyMediaType = BodyMediaTypeOrFallback(request);
         var contentEncodingHeader = request.Headers.HeaderOfOrDefault(ResponseHeader.ContentEncoding, RequestHeader.WithContentEncoding());
         var contentEncoding = ContentEncoding.ParseFromHeader(contentEncodingHeader?.Value);
         return new RequestData(request.Body !, ContentMediaType.ParseFromDescriptor(bodyMediaType), contentEncoding);
     }) :
Ejemplo n.º 4
0
        public static ParameterResolver <T> Path <T>(int position)
        => ParameterResolver <T> .Create(
            Type.Path,
            (request, mappedParameters) =>
        {
            var value = mappedParameters.Mapped[position].Value;
            if (value is T)
            {
                return((T)value !);
            }

            throw new ArgumentException(
                $"Value {value} is of mimeType {mappedParameters.Mapped[position].Type} instead of {typeof(T).Name}");
        });
Ejemplo n.º 5
0
 public static ParameterResolver <Header> Header(string headerName)
 => ParameterResolver <Header> .Create(
     Type.Header,
     (request, mappedParameters) => request.HeaderOf(headerName) !);
Ejemplo n.º 6
0
 public static ParameterResolver <T> Body <T>(IMapper mapper)
 => ParameterResolver <T> .Create(
     Type.Body,
     (request, mappedParameters) => (T)mapper.From(request?.Body?.ToString(), typeof(T)) !);