Linked Questions

Popular Questions

Replicate curl with fetch function in js

Asked by At

I have an application that returns a buffer with a Http request. When I run curl in my terminal I get a proper response:

Curl:

curl -s -X GET \  "url" \  -H "authorization: Bearer token" \  -H "content-type: application/json"

Response:

Pendiente now has [{"Key":"73ef53d2848708ae3288db3afb69ee85a663eba2ab147e83494f65585d171a2d","Record":{"cantidad":"100","docType":"fabricacion","estado":"Pendiente","id":"73ef53d2848708ae3288db3afb69ee85a663eba2ab147e83494f65585d171a2d","mercado":"dercadona","owner":"jose","producto":"manzanas","usuario":"jose"}},{"Key":"9b2d52becf9620971c7fd31c54b817533157cb2c7186dd3835f4c502742418b5","Record":{"cantidad":"200","docType":"fabricacion","estado":"Pendiente","id":"9b2d52becf9620971c7fd31c54b817533157cb2c7186dd3835f4c502742418b5","mercado":"mercadona","owner":"jose","producto":"peras","usuario":"jose"}}] after the move

I am trying to get the json part from that response with fetch using js (the fetch goes inside another fetch). I've tried different methods but I can't manage to get it properly

return fetch(url_get_tx,{
        method: 'get',
        headers: {
            'Content-type': 'multipart/form-data',
            'authorization': 'Bearer '+data.token
        }
    }
.then(function(data) {
    var reader = data.body.getReader();
    return reader.read()
    console.log("here");
    console.log(typeof(reader));
    console.log(reader);

})

Many thanks

Related Questions