POST for corresponding collection in WEB API 2 with OData 4
I want to have a route like:
/Accounts(id)/Orders
where can I POST to create an order. I cannot find a way to add this route using OData in WebApi. For GET, there is a convention for getting related collections, but I cannot find any convention for placing new objects in the corresponding collection.
Is there a standard way to handle this POST request using Web API 2 and OData 4?
+3
Cosmin
source
to share
1 answer
Added the following method attributes and it worked:
[HttpPost]
[ODataRoute("Accounts({key})/Orders")]
public IHttpActionResult Orders([FromODataUri] string key, OrderDto orderDto)
{
}
+3
Cosmin
source
to share