none
Why there is a need to set content type in response for REST API? RRS feed

  • Question

  • I have developed a WCF REST service containing  some API's which are exposed and can be consume by any application.
    Things works fine but every time I return my response I have to set its content type.

    For example:
    I have a API :  http.<some url>/StudentInfo/id   which  will return student information.
    In Implementation methods I have returned a stream in its response , the body format is json,still I need to set the content type.


    Summarizing: I have no idea why it is a mandate to set contient type of a response ,without setting it I get nothing in browser.

    Please let me know why it is so or any interesting article from which I may learn these concepts.

    Thanks
    Amol.   
    • Edited by Amolrs Thursday, September 1, 2016 8:58 AM
    Thursday, September 1, 2016 8:58 AM

Answers

  • Hi Amol,

    How did you consume Rest Service?

    Based on my understanding, this is related with Accept header in the request of client. Body format is used to format message body, and it did not influence the content type. Accept headers are defined by the client and tell server which content-types it is capable of receiving. You could refer the link below:

    #WCF 4.0 Rest Service setting content type

    http://stackoverflow.com/questions/4822190/wcf-4-0-rest-service-setting-content-type

    To prove this, I think you could use Fiddler to capture your client request, and check the Accept headers.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, September 2, 2016 5:17 AM