예제 #1
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)));
 });
예제 #2
0
    public Response ResponseFrom(Request request, MediaTypeMapper mapper)
    {
        var acceptedMediaTypes        = request.HeaderValueOr(RequestHeader.Accept, DefaultMediaType.ToString());
        var responseMediaTypeSelector = new ResponseMediaTypeSelector(acceptedMediaTypes);
        var responseContentMediaType  = responseMediaTypeSelector.SelectType(mapper.MappedMediaTypes);
        var bodyContent = mapper.From(_entity, responseContentMediaType);
        var body        = Body.From(bodyContent);

        _headers.Add(ResponseHeader.Of(ResponseHeader.ContentType, responseContentMediaType.ToString()));

        return(Response.Of(_version, _status, _headers, body));
    }