Here is an example of how to create a HTTP server with a delete route using C# and ASP.NET Web API:
main.cs1021 chars37 lines
In the above code, we define a DeleteController
class that inherits from ApiController
and has a single action method called Delete
. This method takes an id
parameter and returns an HTTP status code of 200 if the delete action was successful.
We also define a Program
class with a Main
method that creates a new instance of HttpSelfHostConfiguration
with a base URL of http://localhost:8080
. We then map a new HTTP route using the RouteCollectionExtensions.MapHttpRoute
method where we specify that the route is for the DeleteController
and that it should match any URL that is a combination of the base URL, the controller name and an optional id
parameter. We also specify that this route should only handle HTTP DELETE
requests using the constraints
parameter.
Finally, we create a new instance of HttpSelfHostServer
and pass in the configuration object. We then open the server and wait for user input to exit the program.
gistlibby LogSnag