public HttpResponseMessage Get(HttpRequestMessage requestMessage)
 {
     var halDocument = new HalDocument(requestMessage.RequestUri.OriginalString);
     halDocument.AddProperty("Hello", "World");
     return new HttpResponseMessage {
                                     Content = new HalContent(halDocument)
                                 };
 }
예제 #2
0
        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);
        }
예제 #3
0
        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;
        }
예제 #5
0
        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);
        }
예제 #6
0
 public HalContent(HalDocument halDocument)
     : base(halDocument.ToStream())
 {
     Headers.ContentType = new MediaTypeHeaderValue("application/vnd.hal+xml");
 }