Code Monkey home page Code Monkey logo

iplookup-api's Introduction

IP-Lookup API ๐Ÿš€

A simple IP address lookup API, with high performance in mind. It uses pre-collected data and calculates hostname on the fly.

How to setup:

It requires Node.js v16, MongoDB v6, and Redis v6 or higher.

  1. Run npm install
  2. Grab and configure environment variable from .env file
  3. Start mongo db
  4. Start redis-server for data caching
  5. Start redis-server --port 6380 for stats collection
  6. Run node src/loader.js to seed data from csv file
  7. npm start to launch

DEMO

Enter a testing IPv4 address in the {ipaddress} placeholder to get information.

curl --location --request GET 'http://localhost:3001/api/lookup/{ipaddress}'

The above request gets a response like

{
    "city": "Washington",
    "region": "Washington, D.C.",
    "country": "US",
    "latitude": 28.89511,
    "longitude": -70.03137,
    "postal_code": "20004",
    "timezone": "America/New_York",
    "hostname": "example.net"
}

Get usage stats with the following endpoint

curl --location --request GET 'http://localhost:3001/api/stats'

The above request gets a response like

{
    "usage": 21330
}

Wiki

Seeding

src/loader.js is a utility that seeds data from user provided csv file, to the database in batches.

Bulk data update [Todo]

src/loader.js currently performs inserts only, it can be modified to perform upsert operations during seeding process so that older data can be updated. At this time a hash of start and end IP address can be calculated and indexed, later when performing upsert, existing rows can be identified using their hash, and their values can be updated, it will seamlessly update the data while the requests are being served by caching layer.

Caching

There are two levels of caching, first one using Redis that can be shared across multiple instances of the API, and the other caching happens within the server memory to reduce latency under high stress. Server-side cache lives about 180s, and Redis cache for about 300s, so a key invalidates in 480s, and fresh data can be pulled from the database.

iplookup-api's People

Contributors

umrbrwn avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.