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?