protected HttpResponseMessage GetResponse(HalResource resource) { string halDocument = HalDocument.Create(resource, UriFactory.GetRelationsUri(), "rel"); var content = new StringContent(halDocument, Encoding.UTF8, "application/hal+json"); var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = content }; return response; }
public static string Create(HalResource halResource, string relationsUri = null, string relationPlaceholder = null) { if (relationsUri != null) { // Add curies to the links of the top level resource. halResource.Links.Curies = new List<CurieLink> { new CurieLink(relationsUri, relationPlaceholder) }; } var jsonSettings = new JsonSerializerSettings { Formatting = Formatting.Indented, NullValueHandling = NullValueHandling.Ignore, ContractResolver = new CamelCasePropertyNamesContractResolver() }; string halDocument = JsonConvert.SerializeObject(halResource, jsonSettings); return halDocument; }
internal HalDocument(HalResource root) : this((string)null) { Root = root; }
public HalDocument(string href, string rel = "self") { Namespaces = new List<Tuple<string, Uri>>(); Root = new HalResource(rel, href); }
public PropertyFinder(HalResource root) { _root = root; }
private static void InternalFindAllLinks(HalResource resource, IList<HalLink> outList) { outList.Add(resource.ResourceLink); foreach (var node in resource.Contents.Values.OfType<HalLink>()) { outList.Add(node); } foreach (var node in resource.Contents.Values.OfType<HalResource>()) { InternalFindAllLinks(node, outList); } }