I'm doing some research on how to implement hypermedia for a particular resource, but can't find a real implementation example, just abstractions...
You know, in various articles, the guy create a method like:
public List<Link> CreateLinks(int id)
{
...//Here the guy put these three dots, whyyyyyyyyyy?
}
What I have so far:
public Appointment Post(Appointment appointment)
{
//for sake of simplicity, just returning same appointment
appointment = new Appointment{
Date = DateTime.Now,
Doctor = "Dr. Who",
Slot = 1234,
HyperMedia = new List<HyperMedia>
{
new HyperMedia{ Href = "/slot/1234", Rel = "delete" },
new HyperMedia{ Href = "/slot/1234", Rel = "put" },
}
};
return appointment;
}
And the Appointment class:
public class Appointment
{
[JsonProperty("doctor")]
public string Doctor { get; set; }
[JsonProperty("slot")]
public int Slot { get; set; }
[JsonProperty("date")]
public DateTime Date { get; set; }
[JsonProperty("links")]
public List<HyperMedia> HyperMedia { get; set; }
}
public class HyperMedia
{
[JsonProperty("rel")]
public string Rel { get; set; }
[JsonProperty("href")]
public string Href { get; set; }
}
Is there a proper way to that? I mean, without hard coding the links? How to create them dynamically for a given type, i.e. Appointment class?
I'm using c# Webapi, not c# MVC.