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 hal = HalDocument.Create(new Uri("http://example.org")); | |
hal.AddNamespace("td", new Uri("http://mytodoapp.com/rels/")); | |
hal.AddLink("td:search", new Uri("/todo-list/search;{searchterm}",UriKind.Relative)); | |
hal.AddLink("td:description", new Uri("/todo-list/description", UriKind.Relative)); | |
hal.AddProperty("created_at", "2010-01-16"); | |
hal.AddProperty("updated_at", "2010-02-21"); | |
hal.AddProperty("summary", "An example list"); | |
hal.CreateResource("td:owner", new Uri("http://range14sux.com/mike")) |
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
WITH XMLNAMESPACES(DEFAULT 'http://www.w3.org/2005/Atom') | |
SELECT 'Customers' AS 'title', | |
'' AS 'subtitle', | |
'http://tavis.net/Customers' AS 'id', | |
REPLACE(CONVERT(varchar,(SELECT MAX(COALESCE(ModifiedDate,CreatedDate)) FROM tblCustomer), 121),' ','T') + 'Z' AS 'updated', | |
(SELECT cu.Code AS 'title', | |
REPLACE(CONVERT(varchar,COALESCE(ModifiedDate,CreatedDate) , 121),' ','T') + 'Z' AS 'updated', | |
'Darrel Miller' AS 'author/name', | |
'http://tavis.net/Customer/' + LTRIM(STR(cu.ID)) AS 'id', | |
(SELECT * |
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.Linq; | |
using System.Text; | |
using System.Xml.Linq; | |
using System.Linq; | |
namespace LinqApplePropertyList { | |
class Program { | |
static void Main(string[] args) { |
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 SimpleObjectContent<T> : HttpContent | |
{ | |
private readonly T _outboundInstance; | |
private readonly HttpContent _inboundContent; | |
private readonly MediaTypeFormatter _formatter; | |
// Outbound constructor | |
public SimpleObjectContent(T outboundInstance, MediaTypeFormatter formatter) | |
{ | |
_outboundInstance = outboundInstance; |
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 static class FormatterCollectionExtensions | |
{ | |
public static Tuple<MediaTypeFormatter,MediaTypeHeaderValue> Negotiate<T>(this MediaTypeFormatterCollection formatters, HttpRequestMessage requestMessage) | |
{ | |
var formatSelector = new FormatterSelector(); | |
MediaTypeHeaderValue mediaType = null; | |
var response = new HttpResponseMessage() {RequestMessage = requestMessage}; | |
var formatter = formatSelector.SelectWriteFormatter(typeof(T), new FormatterContext(response, false), formatters, out 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
<?xml version="1.0" encoding="utf-8"?> | |
<resource href="/orders"> | |
<link rel="self" href="/orders"/> | |
<link rel="relatedResource1" href="/orders/relatedResource1"/> | |
<link rel="relatedResource2" href="/orders/relatedResource2"/> |
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 LoggingFormatterSelector : IFormatterSelector | |
{ | |
private readonly FormatterSelector _FormatterSelector = new FormatterSelector(); | |
public new MediaTypeFormatter SelectReadFormatter(Type type, FormatterContext formatterContext, IEnumerable<MediaTypeFormatter> formatters) | |
{ | |
string descriptFormatterContext = GetDescriptFormatterContext(formatterContext); | |
Console.WriteLine("Selecting Read Formatter for type {0} based on formatter context: {1}", type.Name, descriptFormatterContext); |
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 IWantJSONDammit : DelegatingHandler | |
{ | |
protected override Task<HttpResponseMessage> SendAsync( | |
HttpRequestMessage request, CancellationToken cancellationToken) | |
{ | |
request.Headers.Accept.Clear(); | |
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | |
return base.SendAsync(request,cancellationToken); |
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 / | |
=> | |
200 OK | |
Content-Type: application/hal+json | |
{ | |
"_links": { | |
"self": { "href": "/" }, | |
"urn:tekpub:login": { "href": "/login" } |
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 / | |
=> | |
200 OK | |
Content-Type: application/hal+json | |
{ | |
"_links": { | |
"self": { "href": "/" }, | |
"urn:tekpub:login": { "href": "/login" } | |
} |
OlderNewer