Simple GET Request

Asked

Viewed 20 times

0

I’m trying to consume a Federal Board of Medicine API but so far unsuccessful.

This is a very simple GET request: https://portal.cfm.org.br/api_rest_php/api/v1/medicos/buscar_foto/9666/PA

Where the last 2 parameters are the doctor’s CRM and the state acronym (UF).

I’m trying for Ode.js with the code below:

const url = 'https://portal.cfm.org.br/api_rest_php/api/v1/medicos/buscar_foto/9666/PA'

axios.get(url)
    .then(retorno => {
      res.json(retorno.data)
    })
    .catch(err => {
      res.json(err)
    })

The problem is that return.data always returns empty, but calling the same URL in the browser data is returned correctly.

What am I doing wrong?

1 answer

0

I tried to replicate the problem and it didn’t happen, it works correctly. Since you don’t have all your code, I don’t know if something is missing, see below:

var url = 'https://portal.cfm.org.br/api_rest_php/api/v1/medicos/buscar_foto/9666/PA';
axios.get(url)
     .then(retorno => {
       console.log(retorno.data);
     })
     .catch(err => {
       res.json(err)
    });
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.21.1/axios.min.js"></script>

I suggest inspecting what you have in "return" to see what comes back in your request. There is a "status" property that tells you whether or not it was successful.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.