我正在做關於如何實現特定資源超媒體的一些研究,但無法找到一個真正的實現例子,只是抽象...正確的方法來創建在C#中的WebAPI超媒體
要知道,在各種物品,這傢伙創建等的方法:
public List<Link> CreateLinks(int id)
{
...//Here the guy put these three dots, whyyyyyyyyyy?
}
我有什麼至今:
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;
}
和約會類:
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; }
}
有沒有適當的方法呢?我的意思是,沒有硬編碼鏈接?如何爲給定類型動態創建它們,例如Appointment類?我正在使用c#Webapi,而不是c#MVC。
謝謝。所以我的模型並非如此...接受答案。 –