Country api.service.ts
const baseUrl = 'https://restcountries.com/v3.1';
@Injectable({
providedIn: 'root',
})
export class CountryApiService {
constructor(private http: HttpClient) {}
findByName(query: string): Observable<Country[]> {
const params = new HttpParams()
.set('fields', 'name,region');
const url = `${baseUrl}/name/${query}`;
return this.http.get<Country[]>(url, { params: params });
}
}