Web Api: recommended way to return json string

前端 未结 4 782
一个人的身影
一个人的身影 2020-12-10 15:57

I\'ve got a couple of services which already receive a json string (not an object) that must be returned to the client. Currently, I\'m creating the HttpResponseMessag

4条回答
  •  失恋的感觉
    2020-12-10 16:26

    Leave the response format to the content negotiation in order to be REST compliant, the client should decide what format it wants.

    In your web API action, you should just return Ok(your object) and web API will see what is the best format to return it.

    If you need to omit other formatters, then just remove the other MediaTypeFormatter objects just as Nkosi advised.

提交回复
热议问题