When working with microservices, you will find yourself with various apps that need users to select a country or a city.
There are a lot of providers for such services out there, this however is an in-house solution that you can spin in a couple of seconds.
The dataset is based on Juanmah's work, but slightly striped.
- create an azure function app in Azure.
- read the csv.
- respond with the requested data.
- clone repository.
- create a dotnet (3.1 we are still waiting for 6) Function App in azure.
- pulbish to function to the above function.
- When publishing make sure the option "run from a package" is false or 0. This makes wwwroot folder in Kudu readonly as the docs state.
- Create a folder, "Data" , using Kudu in the wwwwroot folder of the function.
- Upload your csv file to the Data folder in Kudu.
- test your function.
- without parameter country you will get a list of all countries in the world.
- with a paramter you will get a list of cities in that given country.
- Is the data upto date? Yes, cities take time to form. If a city is missing please let me know so that I can update the dataset.
- Can the data be improved Yes, if the need arises we could add support for continent and other related data.
- How is the performance? It is just fine, check the response times in the pictures above.
- I want a faster response, can that be done? Yes, strip the file and remove fields that you don't need.
- Kudu cannot gives me a ERROR 409 Conflict ! Set WEBSITE_RUN_FROM_PACKAGE to 0 in your function app configuration in Azure. This app service feature makes the wwwroot folder readonly as referenced above.
- Well my local solution is not working ! Azure and a local development enviromrmnt have diffirent file structures, for debugging puposes change the root directory line to :
var rootDirectory = Path.GetFullPath(Path.Combine(binDirectory, "..","..","..",".."))
;