We'll use Postman to test a RESTful OData Web API application, sending an HTTP DELETE request. We'll use a working OData Web API ODataController built in a previous tutorial, and we'll delete a record using Postman :
In order to get Postman installed , go to the Chrome Tools >> Extensions , search for "Postman" and install the App .
HTTP DELETE Request to a RESTful ODataController Web API with Postman
Now let's see how to call the OData Web API to delete an item : in order to setup the ODataController , there will be an ODataModelBuilder at the "Register" method called from the Global.asax file : it's important that the EntitySet name MUST be the same name of the Controller , therefore we'll look for a "NotesController" at the application :
Because there is a route prefix set ( "ODataV4" ) , we'll also append it to the URL :
Why are we checking this ? Because we want to know what is ODataController method expecting : in our case , it expects a URI which must include an integer "key" ID ( "[FromODataURI]" ) .
The Port of the application can be extracted from the Web tab at the application properties:
Put all of this together , and you have the URI for the DELETE request :
Important : OData is case sensitive : therefore , if you type "notes" instead of "Notes" , you will not obtain any data.
After setting the URI and the DELETE method , write the "Content-Type" header :
Send the request :
The request details can be seen this way :
In the meantime , the ODataController at the RESTful WebAPI have handled the request with the ID in the ODataURI :
The action method renders a response with code 410 "GONE" , to express that the record has been deleted , and Postman exposes it :
That's all...In this tutorial we've learned how to send an HTTP DELETE Request to a RESTful ODataController Web API Service using Postman.
By Carmel Shvartzman
כתב: כרמל שוורצמן