0

Using the Halcyon .NET library (https://github.com/visualeyes/halcyon), I can generate the HAL (http://stateless.co/hal_specification.html) output that I need for my prototype API.

However, I would like to add curies in to document additional semantics of some of my rel types. I don't see a way to add curies as a link using the supplied API.

I've tried:

public class LinkBuilder
{
    public static readonly Link[] Curies =
    {
        new Link("curies", "http://test.com/api/docs/rels/{rel}", replaceParameters: false, isRelArray: true)
    };
    public static Link AsProductFamilyLink(int familyId)
    {
        return new Link("tns:product-family", $"/product-family/{familyId}");
    }

    /* snip */

}

but this results in output missing the crucial name attribute of the curie:

{
    "id": 2,
    "name": "Chips",
    "unitPrice": 0,
    "_links": {
        "delete-product": {
            "href": "/product/2",
            "method": "DELETE",
            "title": "Delete product"
        },
        "tns:product-family": {
            "href": "/product-family/1"
        },
        "self": {
            "href": "/product/2",
            "method": "GET"
        },
        "curies": [
            {
                "href": "http://test.com/api/docs/rels/{rel}",
                "templated": true
            }
        ]
    }
}

How can I generate the curies link correctly? (Maybe a different library?) To be clear, the expected "curies" array should look like:

[
   {
      "name": "tns",
      "href": "http://test.com/api/docs/rels/{rel}",
      "templated": true
   }
]
goofballLogic
  • 37,883
  • 8
  • 44
  • 62

1 Answers1

1

Set the Name property of the CURIE link:

new Link("curies", "http://test.com/api/docs/rels/{rel}", replaceParameters: false, isRelArray: true)
{
    Name = "tns"
};
Dietatko
  • 374
  • 1
  • 13