Answer the question
In order to leave comments, you need to log in
How to get the capital of a certain country using the API?
There was a small idea, purely for practice.
I want to create a mini application on pure js, where the user enters a list of countries in the input field, which are transferred to an array, and from the array the list should be created on the site in the form: "Country - Its capital". The problem arose only in obtaining the capital. Is there any API that can be used to get the desired country and its capital?
As an option, of course, write the database in json format yourself, and then there will be no problems, but it takes a very long time to do it yourself, and I think it’s not reasonable.
I found only the API, which lists absolutely all the cities of the desired country, which I do not need, since the capital is not allocated there in any way.
Thank you!
Answer the question
In order to leave comments, you need to log in
https://restcountries.eu/
Here, in the example for the endpoint https://restcountries.eu/rest/v2/alpha/col
, there is a capital parameter in the response, and already on another endpoint, you can get information about the city
Upd. It can be even simpler, specify a specific field at the /country/<countryname> endpoint to get only the capital
answer on SO
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question