Search code examples
httprequestfiwarefiware-wirecloud

Wirecloud / Fi-Ware edit request header in http.makerequest method


I’m working on an widget for the fiware mashup. It needs to get data in json from a server. I’ve realized that with the MashupPlatform.http.makeRequest.

The problem is, the server sends xml back, if I don’t ask to get json. I don’t find any option in the widget api to to do it so. (like the curl option --header 'Accept: application/json')


Solution

  • As you have said, when you perform an HTTP request, you should add the Accept header to specify the response format. When you are using the MashUp Platform to make requests, you can specify the headers by adding the object "requestHeaders" in the options parameter. For example:

    MashupPlatform.http.makeRequest("http://YOUR_SERVICE_URL/PATH", { "requestHeaders": {"Accept":"application/json"}});
    

    You can check all the options that you can include in a HTTP request in the documentation: https://wirecloud.readthedocs.org/en/latest/widgetapi/widgetapi/#request-options-general-options

    Best Regards