0

I'm using fetch to retrieve data from my api, the response that returns according to the logs is :

{
    "statusCode": 200,
    "headers": {
        "Content-Type": "application/json"
    },
    "body": "[{\"text\": \"1\", \"email\": \"test1@asfsaf.com\"}, {\"text\": \"3\", \"email\": \"test3@asfsaf.com\"}, {\"text\": \"2\", \"email\": \"test2@asfsaf.com\"}]"
}

but on angular when debugging:

body: null
bodyUsed: false
headers: Headers {append: function, delete: function, get: function, has: function, set: function, …}

ok: false

redirected: false

status: 0

statusText: ""

type: "opaque"

url: ""

the code I'm using to call the api is:

getLastReviews()
  {
    return fetch (
        ApiService.url ,
        {
          headers: {
            'Content-Type': 'application/json',
          },
          method: 'GET',
          mode: 'no-cors',
        }, 
      )
  }

the code on the component :


  constructor(private api : ApiService) { }

  recent_reviews
  ngOnInit()
  {
    this.getRecent()
  }
  async getRecent(){
    let res = await this.api.getLastReviews()
    debugger
    let data = await res.json()
    this.recent_reviews = data
  }
}

I've tried calling this url using postman and it's working with no errors although when entering the url in the browser I also get an empty response - {}. does anyone knows where the problem might be? thanks!

Shlok Nangia
  • 2,355
  • 3
  • 16
  • 24
ofek edut
  • 31
  • 1
  • 5

0 Answers0