0

For some unknown reason, Stackblitz cannot handle requests to certain APIs. It has no problem getting data from sonplaceholder.typicode.com, but cannot get data from https://swapi.dev/api/planets/1/. When trying to fetch from SWAPI, it results in a console error saying HttpErrorResponse/ProgressEvent

Here is the Stackblitz, with the code of concern copied below:

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent  {

  readonly URL = 'https://jsonplaceholder.typicode.com/posts';    // works fine
  // readonly URL = 'https://swapi.dev/api/planets/1/';           // HTTPErrorResponse

  posts: Observable<any>;

  constructor(private http: HttpClient) {}

  getPosts() {
    this.posts = this.http.get(this.URL)    
  }
}

What is special about jsonplaceholder.typicode that Stackblitz lets us fetch data from it, and how can I get SWAPI to work too? And further, how can I mimic that on my own server?

CodyBugstein
  • 21,984
  • 61
  • 207
  • 363

1 Answers1

0

I just checked your code and currently it is working fine. The issue might have been due to a temporary downtime of a service itself or other networking issues, hence it is always a good idea to explore details of an error and see what is a nature of a problem.

Juriy
  • 5,009
  • 8
  • 37
  • 52