我要编写一个RESTful API,我的需求是对“Transaction”对象调用方法,我想知道应该如何使用适当的URI模板调用Post/PUT方法,以便在不使用Uri映射中的“动词”的情况下创建/更新Transaction资源。
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "/Transaction/{**What to write here ????**}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
public Transaction AddTransaction(Transaction transaction)
{
return AddTransactionToRepository(transaction);
}
[OperationContract]
[WebInvoke(Method = "PUT", UriTemplate = "/Transaction/{**What to write here ????**}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
public Transaction UpdateTransaction(Transaction transaction)
{
return UpdateTransactionInRepository(transaction);
}
请注意,我希望应用最佳实践进行URI映射,并且不想在其中使用“动词”,只想使用“名词”。同时,请告诉我客户端如何访问这些具有唯一URI的Post和Put方法。谢谢。