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
// Server | |
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.Linq; | |
using System.Net.Http; | |
using System.Net.Http.Headers; | |
using System.Text; |
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
<resource href="/ErrorLog/2323234"> | |
<resource rel="http://example.com/probs/out-of-credit" ref="/ErrorLog/2323234/details"> | |
<title>"You do not have enough credits."</title> | |
<detail>"Your current balance is 30, but that costs 50."</title> | |
<balance>30</balance> | |
<account>http://api.example.com/account/12345</account> | |
</resource> | |
</resource> |
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 interface IHttpService<T> { | |
HttpResponseMessage<T> Get(HttpRequestMessage<T> request); | |
HttpResponseMessage<T> Put(HttpRequestMessage<T> request); | |
HttpResponseMessage<T> Post(HttpRequestMessage<T> request); | |
HttpResponseMessage<T> Delete(HttpRequestMessage<T> request); | |
} |
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
GET POST /gists | |
GET /gists/public | |
GET /gists/starred | |
GET PATCH DELETE /gists/:id | |
GET /gists/:gist_id/comments | |
PUT /gists/:id/star | |
POST /gists/:id/fork | |
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
var router = new ApiRouter("api").DispatchTo<RootController>() | |
.Add(new ApiRouter("Contacts").DispatchTo<ContactsController>()) | |
.Add(new ApiRouter("Contact").WithHandler(new LoggingHandler()) | |
.Add(new ApiRouter("{contactid}") | |
.WithConstraint("contactid", @"\d+") | |
.DispatchTo<ContactController>() | |
.Add(new ApiRouter("Address") | |
.Add(new ApiRouter("{addressid}") |
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 SimpleFormatter<T> : MediaTypeFormatter | |
{ | |
private readonly Action<T,Stream> _write; | |
private readonly Func<Stream,T> _read; | |
public SimpleFormatter(MediaTypeHeaderValue mediatype, Func<Stream,T> read, Action<T,Stream> write) | |
{ | |
_write = write; | |
_read = read; | |
SupportedMediaTypes.Add(mediatype); |
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
// CustomerController | |
public override Stream Get() { | |
var model = new CustomerModel(Container, _CustomerId); | |
var view = new CustomerDetailView(Container); | |
return view.Render(model); |
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 ThroughputMessageHandler : DelegatingHandler | |
{ | |
private readonly ILogger _logger; | |
private Timer _timer; | |
private int _count; | |
public ThroughputMessageHandler(ILogger logger) | |
{ | |
_logger = logger; | |
_count = 0; | |
_timer = new Timer(new TimerCallback(timerCallback),null,1000,1000); |
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 PlainTextFormatter : MediaTypeFormatter | |
{ | |
public PlainTextFormatter() | |
{ | |
SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/plain")); | |
} | |
protected override System.Threading.Tasks.Task<object> OnReadFromStreamAsync(Type type, System.IO.Stream stream, HttpContentHeaders contentHeaders, FormatterContext formatterContext) | |
{ | |
return new Task<object>(() => |
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
[TestMethod] | |
public void ConnegTest() | |
{ | |
var selector = new FormatterSelector(); | |
var response = new HttpResponseMessage(); | |
response.RequestMessage = new HttpRequestMessage(); | |
var headers = response.RequestMessage.Headers; | |
headers.Accept.Add(new MediaTypeWithQualityHeaderValue("text/plain")); | |
headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json",0.8)); |