✅ Is it possible to access a Controller's URI at runtime?

I'm not well versed in MVC structures, so this very well could be a XY problem. Let me know if it is a bad idea to begin with.

I'm trying to create a GET endpoint for /collections which returns Collections. One Collection always contains a nested Model
User
.

On its own, this is not a problem. However, I am creating my API based around application/hal+json, which requires Resources to have a link to point to their exact location.

So when accessing a returned Collection, I could use its related link if I wish to access it directly instead.
It looks sort of like this:

Endpoints:
/collections
/collections/{uuid}

{
  "_links": {
    "self": {
      "href": "http://foo-api/collections"
    }
  },
  "_embedded": {
    "collection": [

      {
        "fooProp": "I'm a specific collection",
        "_links": {
          "self": {
            "href": "http://foo-api/collections/62fcac86a39a11ef"
          }
        }
      }

    ]
  }
}


This is all well and good, but I have some concerns with generating the embedded collection's link.
If I hardcode it as $"http://foo-api/collections/{uuid}", then I would have to change the domain in every location where I did it.

Is it possible to access the CollectionController#GetById(string uuid) somehow and extract its URI at runtime?
Was this page helpful?