I've been attempting to connect to the Wikipedia API using Angular 7, but I keep receiving null results.
When I make a call directly to the Wikipedia API site with the following URL: https://en.wikipedia.org/api/rest_v1/page/summary/Addax?redirect=true, I successfully receive a properly formatted JSON response.
However, when I make the same request from my application, the response body is empty.
Below is the code snippet for the HTTP request:
export class WikirestService {
constructor( private http: HttpClient) { }
getWiki(title: string) {
const tempTitle = title.replace(' ', '_') + '?redirect=true';
const baseUrl = 'https://en.wikipedia.org/api/rest_v1/page/summary/';
return this.http.get<WikiSummary>(baseUrl+tempTitle);
}
}
And here is the structure of the WikiSummary Model:
export class WikiSummary {
type?: string;
title?: string;
displaytitle?: string;
namespace?: Namespace;
wikibase_item?: string;
titles?: Titles;
pageid?: number;
thumbnail?: Originalimage;
originalimage?: Originalimage;
lang?: string;
dir?: string;
revision?: string;
tid?: string;
timestamp?: Date;
description?: string;
content_urls?: ContentUrls;
api_urls?: APIUrls;
extract?: string;
extract_html?: string;
}
Despite setting up the model correctly, it always remains null. Even after logging the results, they are still null. Below is how I call the service from the component:
this.wikiRest.getWiki(this.title).subscribe(data => { temp = data; });
I have been struggling with this issue for hours and would greatly appreciate some assistance. This is my first time encountering difficulties while working with an External API.