Der Endpunkt /v1/select/countries gibt eine leichtgewichtige Liste aller Laender mit nur den Feldern id und name zurueck, optimiert fuer Dropdown-Menues und Formulareingaben.
GET https://api.countrydataapi.com/v1/select/countries
Fuegen Sie Ihren API-Schluessel als Query-Parameter hinzu:
?apikey=ihr-api-schluessel
Ihr API-Schluessel ist wie ein Passwort, halten Sie ihn sicher. Holen Sie sich Ihren Schluessel vom Konto-Dashboard.
| Parameter | Typ | Erforderlich | Beschreibung |
|---|---|---|---|
apikey |
string | Ja | Ihr API-Authentifizierungsschluessel |
lang |
string | Nein | Sprachcode fuer Laendernamen (Standard: en) |
en - Englisch (Standard)es - Spanischpt - Portugiesischfr - Franzoesischde - Deutschit - Italienischcurl "https://api.countrydataapi.com/v1/select/countries?apikey=ihr-api-schluessel&lang=de"
const API_KEY = 'ihr-api-schluessel';
async function laenderLaden() {
const response = await fetch(
`https://api.countrydataapi.com/v1/select/countries?apikey=${API_KEY}&lang=de`
);
const data = await response.json();
return data;
}
import axios from 'axios';
const response = await axios.get(
'https://api.countrydataapi.com/v1/select/countries',
{
params: {
apikey: 'ihr-api-schluessel',
lang: 'de',
},
}
);
import requests
response = requests.get(
'https://api.countrydataapi.com/v1/select/countries',
params={
'apikey': 'ihr-api-schluessel',
'lang': 'de'
}
)
data = response.json()
<?php
$apiKey = 'ihr-api-schluessel';
$url = "https://api.countrydataapi.com/v1/select/countries?apikey={$apiKey}&lang=de";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
?>
// country.service.ts
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
interface Country {
id: string;
name: string;
}
interface ApiResponse {
success: boolean;
data: Country[];
}
@Injectable({
providedIn: 'root'
})
export class CountryService {
private readonly API_KEY = 'ihr-api-schluessel';
private readonly BASE_URL = 'https://api.countrydataapi.com/v1';
constructor(private http: HttpClient) {}
getCountries(lang: string = 'de'): Observable<Country[]> {
const params = new HttpParams()
.set('apikey', this.API_KEY)
.set('lang', lang);
return this.http.get<ApiResponse>(
`${this.BASE_URL}/select/countries`,
{ params }
).pipe(
map(response => response.data)
);
}
}
// country-select.component.ts
import { Component, OnInit } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { CountryService } from './country.service';
@Component({
selector: 'app-country-select',
standalone: true,
imports: [CommonModule, FormsModule],
template: `
<div *ngIf="loading">Laender werden geladen...</div>
<div *ngIf="error" class="error">{{ error }}</div>
<select
*ngIf="!loading && !error"
[(ngModel)]="selectedCountry"
(ngModelChange)="onCountryChange($event)"
>
<option value="">Land auswaehlen...</option>
<option *ngFor="let country of countries" [value]="country.id">
{{ country.name }}
</option>
</select>
`
})
export class CountrySelectComponent implements OnInit {
countries: any[] = [];
selectedCountry = '';
loading = true;
error: string | null = null;
constructor(private countryService: CountryService) {}
ngOnInit() {
this.countryService.getCountries('de').subscribe({
next: (data) => {
this.countries = data;
this.loading = false;
},
error: (err) => {
this.error = 'Fehler beim Laden der Laender';
this.loading = false;
}
});
}
onCountryChange(countryId: string) {
console.log('Ausgewaehltes Land:', countryId);
// Bundeslaender laden, Event emittieren, etc.
}
}
{
"success": true,
"data": [
{
"id": "66c7a6c9e4bda21f4ab10ef2",
"name": "Afghanistan"
},
{
"id": "66c7a6c9e4bda21f4ab10ef3",
"name": "Albanien"
},
{
"id": "66c7a6c9e4bda21f4ab10ef4",
"name": "Algerien"
}
// ... weitere Laender (200+ insgesamt)
]
}
| Feld | Typ | Beschreibung |
|---|---|---|
success |
boolean | Zeigt an, ob die Anfrage erfolgreich war |
data |
array | Array von Laender-Objekten |
data[].id |
string | Eindeutige Laenderkennung (MongoDB ObjectId) |
data[].name |
string | Laendername in der angeforderten Sprache |
{
"success": false,
"error": {
"code": "INVALID_API_KEY",
"message": "Der bereitgestellte API-Schluessel ist ungueltig"
}
}
Siehe die Fehlercode-Dokumentation fuer alle moeglichen Fehlercodes.
Der Select-Endpunkt ist fuer minimale Bandbreite optimiert:
/v1/countries/all): ~500KB (enthaelt alle Laenderdaten)/v1/select/countries): ~15KB (nur id und name)Das macht den Select-Endpunkt 97% kleiner und perfekt fuer Formular-Dropdowns!
Dieser Endpunkt verbraucht 1 Token pro Anfrage.
Tipp: Speichern Sie die Antwort im localStorage oder im Zustand Ihrer Anwendung zwischen. Laender aendern sich selten, daher koennen Sie sicher fuer 7+ Tage cachen.
<select id="country">
<option value="">Land auswaehlen...</option>
<!-- Via JavaScript befuellt -->
</select>
<script>
async function laenderBefuellen() {
const response = await fetch(
'https://api.countrydataapi.com/v1/select/countries?apikey=ihr-api-schluessel&lang=de'
);
const { data } = await response.json();
const select = document.getElementById('country');
data.forEach(country => {
const option = new Option(country.name, country.id);
select.add(option);
});
}
laenderBefuellen();
</script>
import { useState, useEffect } from 'react';
function CountrySelect() {
const [countries, setCountries] = useState([]);
useEffect(() => {
fetch('https://api.countrydataapi.com/v1/select/countries?apikey=ihr-api-schluessel&lang=de')
.then(res => res.json())
.then(({ data }) => setCountries(data));
}, []);
return (
<select>
<option value="">Land auswaehlen...</option>
{countries.map(country => (
<option key={country.id} value={country.id}>
{country.name}
</option>
))}
</select>
);
}
<script setup>
import { ref, onMounted } from 'vue';
const countries = ref([]);
onMounted(async () => {
const response = await fetch(
'https://api.countrydataapi.com/v1/select/countries?apikey=ihr-api-schluessel&lang=de'
);
const { data } = await response.json();
countries.value = data;
});
</script>
<template>
<select>
<option value="">Land auswaehlen...</option>
<option v-for="country in countries" :key="country.id" :value="country.id">
{{ country.name }}
</option>
</select>
</template>
Speichern Sie Laender im localStorage zwischen, um API-Aufrufe zu minimieren:
const CACHE_KEY = 'countries_cache';
const CACHE_DURATION = 7 * 24 * 60 * 60 * 1000; // 7 Tage
async function getLaender() {
// Zuerst Cache pruefen
const cached = localStorage.getItem(CACHE_KEY);
if (cached) {
const { data, timestamp } = JSON.parse(cached);
if (Date.now() - timestamp < CACHE_DURATION) {
return data;
}
}
// Von API abrufen
const response = await fetch(
'https://api.countrydataapi.com/v1/select/countries?apikey=ihr-api-schluessel&lang=de'
);
const { data } = await response.json();
// Im Cache speichern
localStorage.setItem(CACHE_KEY, JSON.stringify({
data,
timestamp: Date.now()
}));
return data;
}
Dynamisch zwischen Sprachen wechseln:
function laenderLaden(sprache = 'de') {
return fetch(
`https://api.countrydataapi.com/v1/select/countries?apikey=ihr-api-schluessel&lang=${sprache}`
).then(res => res.json());
}
// Auf Spanisch laden
const laenderSpanisch = await laenderLaden('es');
// Auf Franzoesisch laden
const laenderFranzoesisch = await laenderLaden('fr');
Besuchen Sie unsere Preisseite fuer weitere Details.
Hinweis: Das zurueckgegebene
id-Feld ist eine MongoDB ObjectId, die jedes Land eindeutig ueber alle Endpunkte hinweg identifiziert. Verwenden Sie diese ID bei der Abfrage von Bundeslaendern, Staedten oder anderen zugehoerigen Daten.