web api return status code with message c#

For this fire and forget functionality, in your WebAPI controller, do this: The key is the "Response.OnCompleted" part, which allows your code to execute even after reporting HttpStatus 200 OK to the client. Say you have a ProductController that is concerned with CRUD operations on Products, it might have a method like the below: public Product Get(int id) { return dbContext.Products.Get(id); } We have returned the Product type directly making this the simplest solution and . Right click on Controllers, expand Add and click on Controller. If the request resource does not exist, 404 NOT FOUND shall be returned. Many people have different designs for specifying the errors in the API response - some just return status code without any response message, while some describe a simple text message in the body and others specify custom JSON schema for specifying the errors. It means everything about the operation is successful. using Microsoft.AspNetCore.Http; nm, I figured it out, I was foolishly editing the service file and not the controller file. Set HttpResponseMessage as return type for all API methods. I have a similar situation in my webApi. For further actions, you may consider blocking this person and/or reporting abuse, Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. At that point the request is done. Does this run on a new Threadpool thread after request is served? 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 We would like this to be refilled once the order status is cancelled. A Successful DELETE request will remove an existing resource and send 204 NO CONTENT as status code. We're a place where coders share, stay up-to-date and grow their careers. 503 SERVICE UNAVAILABLE If the server is too busy processing other requests, this status code is returned. SignalR is definitely more elegant but gets a little more sticky in a clustered environment. To create a new ASP.NET WebAPI project, follow the below steps one by one. If POST method is not implemented at the server end, 405 METHOD NOT ALLOWED shall be used to inform the client about it. email is in use. Before doing this, I didn't realize that you can actually write