This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TavisUriTemplateHandler : IUrlTemplateHandler | |
{ | |
public IEnumerable<string> GetParameterNames(string template) | |
{ | |
return new UriTemplate(template).GetParameterNames(); | |
} | |
public Uri GetRequestUri(IUrlParameterFormatter urlParameterFormatter, RestMethodInfo restMethod, object[] paramList, string basePath = "") | |
{ | |
string urlTarget = (basePath == "/" ? String.Empty : basePath) + restMethod.RelativePath; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ "collection" : | |
{ | |
"version" : "1.0", | |
"href" : "http://example.org/movies", | |
"items" : [ | |
{ | |
"href" : "http://example.org/movie/1", | |
"data" : [ | |
{"name" : "Title", "value" : "Star Wars"}, | |
{"name" : "Director", "value" : "Lucas"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I can get this... | |
--6151f84b-b24a-41e0-a0ef-31398ab1d44f | |
Content-Disposition: form-data; name="files[image]" | |
--6151f84b-b24a-41e0-a0ef-31398ab1d44f-- | |
With this, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Wrapper Service | |
var customerService = new CustomerService(); | |
var customer = customerService.GetCustomer(22); | |
application.Process(customer); | |
// Hypermedia Centric | |
var customerLink = linkFactory.Create<CustomerLink>(); | |
customerLink.Id = 22; | |
application.FollowLink(customerLink); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Data; | |
using System.Data.SqlClient; | |
using System.Net; | |
using System.Net.Http; | |
using System.Net.Http.Formatting; | |
using System.Threading; | |
using System.Threading.Tasks; | |
using System.Web.Http; | |
using Newtonsoft.Json.Linq; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HtmlFormatter : OutputFormatter | |
{ | |
public HtmlFormatter() | |
{ | |
SupportedEncodings.Add(Encodings.UTF8EncodingWithoutBOM); // Whatever this should be | |
SupportedEncodings.Add(Encodings.UTF16EncodingLittleEndian); // Whatever this should be | |
SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("text/html")); | |
} | |
public override bool CanWriteResult(OutputFormatterContext context, MediaTypeHeaderValue contentType) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ConsoleRequestLogger : DelegatingHandler | |
{ | |
protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | |
{ | |
Console.ForegroundColor = ConsoleColor.Cyan; | |
Console.WriteLine("> {0} {1}",request.Method,request.RequestUri.GetComponents(UriComponents.PathAndQuery, UriFormat.SafeUnescaped)); | |
ProcessHeader(request.Headers, (name, value) => Console.WriteLine("> {0}: {1}", name, value)); | |
if (request.Content != null) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Fact] | |
public void DoesNotPreserveHttpHeaderValueOrderOrCase() | |
{ | |
var response = new HttpResponseMessage(); | |
string input = "Private, max-age=60, s-maxage=60"; | |
response.Headers.TryAddWithoutValidation("Cache-Control", input); | |
var header = response.Headers.First(); | |
var output = string.Join(",", header.Value); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CollectionJsonContent : HttpContent | |
{ | |
private readonly ReadDocument _readDocument; | |
private readonly JsonSerializer _serializer; | |
public CollectionJsonContent(Collection collection) | |
{ | |
_serializer = JsonSerializer.Create(new JsonSerializerSettings | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+using System; | |
+using System.Collections.Generic; | |
+using System.Web.Http; | |
+using WebApiContrib.CollectionJson; | |
+using WebApiContrib.Formatting.CollectionJson; | |
+using WebApiContrib.Formatting.CollectionJson.Infrastructure; | |
+using WebApiContrib.Formatting.CollectionJson.Models; | |
+ | |
+namespace CollectionJson.Controllers | |
+{ |