This is a proof of concept Static JSON GeoIP API using Netlify’s redirect & rewrite rules using country codes (de, us, etc...) to route the response of the GET call to a specific file under a folder structure following the below pattern set in their _redirects file. See this project's available redirects here.

Entry Path Redirected File Path Status Code Country Code
/locale.json /locales/us.json 200 Country=us
/locale.json /locales/nl.json 200 Language=nl

Just replicate the above line with a new Redirected File path with any JSON formatted data you'd like, keep the Status Code the same for all the redirects for this, and then change your desired Country Codes from this list and even language codes from here.

Be sure to test your redirects at Netlify's Playground to make sure you've formatted them correctly. Note: adding too many of these redirects will eventually slow down your site all-together.

Test The Endpoint

The button simply does a fetch call on /locales.json and then returns the current locale within the contraints of the setup redirects.

de.json ~> { "locale": "Germany" }