Get object from response IHttpActionResult c #
I also use the Web API to perform some task, and when the task is completed, the API returns me an object in the OK method.
Code:
[Route("upload")]
[HttpPost]
public async Task<IHttpActionResult> PostFormData()
{
//Create the object
var blob = new BlobUploadModel();
//Do some tasks
...
//Return
return Ok(blob);
}
How can I get this blob object in the response, which I think should be an IHttpActionResult?
Any help is appreciated!
source to share
The Web API will serialize your BlobUploadModel instance to the MIME type specified in the client request header Accept:
. The serialized blob will then be attached to the response body.
Your client that invokes this action will need to deserialize the content of the response body back to the BlobUploadModel. JSON.Net is a great library for serializing / deserializing between JSON objects and CLR objects. To deserialize JSON response to BlobUploadModel using JSON.Net, you can use the following:
var blob = JsonConvert.DeserializeObject<BlobUploadModel>(responseBody);
Keep in mind that your client project needs to know what BlobUploadModel is.
source to share