This challenge demonstrates a simple API which purpose is to provide the country name associated with an IP address. The server exposes a lookup endpoint that rely on multiple vendors for redundancy.
Requirements & Capabilities:
-
Given an IP address, return the associated country name
-
Support multiple vendors (ex.: https://ipstack.com/)
-
Naive cache for IP addresses previously requested
-
Global configurable rate limits of the server per vendor per hour
If the rate limit of one vendor has exceeded, the API fallback to other vendor(s). If the result is not in cache and the rate limit is exceeded for all vendors, it returns an error message.
# Clone repository
$ git clone https://github.com/danielnegri/ip-lookup.js.git
# Install dependencies
$ yarn install
# Make sure to edit and include the API keys (dotenv)
$ cp .env.example .env
$ yarn start
$ docker-compose up
# Start (nodemon)
$ yarn dev
# Testing with a random IP
$ curl http://localhost:3000?ip=109.207.79.75
{"country_name":"Israel"}
# All
$ yarn test
# Unit testing
$ yarn test:unit
# End-to-End
$ yarn test:e2e
See CONTRIBUTING for details on submitting patches and the contribution workflow.
This repository is under the AGPL 3.0 license. See the LICENSE file for details.