public HttpResponseMessage Get(HttpRequestMessage requestMessage) { var halDocument = new HalDocument(requestMessage.RequestUri.OriginalString); halDocument.AddProperty("Hello", "World"); return new HttpResponseMessage { Content = new HalContent(halDocument) }; }
public void CreateHalManuallyUsingBuilder() { var hal = new HalDocument("http://example.org"); hal.CreateResource("foo", "http://example.org/foo").End() .CreateResource("bar", "http://example.org/bar").End(); var stringHal = new StreamReader(hal.ToStream()).ReadToEnd(); Assert.IsNotNull(hal); Assert.IsNotNull(stringHal); }
public void CreateHalManually2() { var hal = new HalDocument("http://example.org"); hal.Contents.Add("foo", new HalResource( "foo", "http://example.org/foo" )); hal.Contents.Add("bar", new HalLink { Rel = "bar", Href = "http://example.org/bar" }); Assert.IsNotNull(hal); }
public HttpResponseMessage Get(HttpRequestMessage requestMesssage) { var response = new HttpResponseMessage(); var rootHal = new HalDocument(requestMesssage.RequestUri.OriginalString); rootHal.AddLink("urn:hapi:template", new Uri("template", UriKind.Relative)); rootHal.AddLink("urn:hapi:partners", new Uri("partner/list",UriKind.Relative)); rootHal.AddLink("urn:hapi:transactions", new Uri("transaction/list", UriKind.Relative)); if (IsAuthenticated(requestMesssage)) { rootHal.AddProperty("Authenticated", "true"); } else { rootHal.AddProperty("Authenticated", "false"); } response.Content = new HalContent(rootHal); return response; }
public void CreateSampleHalFromSpec() { var hal = new HalDocument("http://example.org"); hal.AddNamespace("td", new Uri("http://mytodoapp.com/rels/")); hal.AddLink("td:search", "/todo-list/search;{searchterm}"); hal.AddLink("td:description", "/todo-list/description"); hal.AddProperty("created_at", "2010-01-16"); hal.AddProperty("updated_at", "2010-02-21"); hal.AddProperty("summary", "An example list"); hal.CreateResource("td:owner", "http://range14sux.com/mike") .AddProperty("name","Mike") .AddProperty("age","36") .AddLink("td:friend", "http://mamund.com/") .End(); hal.CreateResource("td:item", "http://home.com/tasks/126") .AddProperty("title", "Find Mug") .AddProperty("details", "Find my mug.") .AddTypedResource("td:attachment", "text/plain", @" ********************************** PLACES MY MUG COULD BE ********************************** - Garden - Roof - Zipcar - Shelf ") .AddLink("td:next", "http://work.com/todos/make-some-tea") .End(); hal.CreateResource("td:item", "http://work.com/todos/make-some-tea") .AddProperty("title", "Make tea") .AddProperty("details", "Mike nice tea that is green. (Gyokuro)") .AddLink("td:prev", "http://home.com/tasks/126") .End(); var stringHal = new StreamReader(hal.ToStream()).ReadToEnd(); Assert.IsNotNull(hal); Assert.IsNotNull(stringHal); }
public HalContent(HalDocument halDocument) : base(halDocument.ToStream()) { Headers.ContentType = new MediaTypeHeaderValue("application/vnd.hal+xml"); }