/geodb-server

A http based API for github.com/daimaou92/geodb

Primary LanguageRustMIT LicenseMIT

GeoDB Server

A HTTP API for geodb

How to Run

  1. Create a new account with Maxmind for Geolite2
  2. Generate a Maxmind License key as instructed here.
  3. Export the generated Key:
export MAXMIND_KEY="abcdefghijklmnop"
  1. Databases are as defined here
  2. Determine a path at which these databases are going to be downloaded. This app will require approx 85MiB of free space for DBs only
  3. Export above path:
export GL2_DBDIR="/tmp/dbdir"
  1. This application can be run with or without auth.
  2. If auth is needed continue else jump to step 11
  3. Create a file with one secret key in each line. Something like this:
CBOI7AIHQcAKhaHVol
7toCW4ndOvNy0ssSot
L44eRv07k2KwndvLQm
EGwSQtwsPjzv1IO75Z
h2UvAAs63ZjhYnISjn
  1. Now export above file:
export GEODB_AUTH_FILE="/tmp/geodb-server-auth.txt"

Any of the keys, one per line, from this file can be used for auth

  1. Test the API (more in the API section below) out for an IP:

Authorized:

curl -H "Authorization:CBOI7AIHQcAKhaHVol" http://localhost:40000/country/ip/1.32.128.0

Unauthorized

curl http://localhost:40000/country/ip/1.32.128.0

How to Build

  1. This application uses protobufs and responds in protobufs only. The proto files are available in src/protos. Naturally to build those you'll need to install protoc.
  2. Once it's available in PATH - just do cargo build or cargo build --release

APIs

This application has 4 APIs. All of them are GET HTTP Requests and each returns one of the protobuf Messages defined in src/protos/geo.proto.

  1. [GET] /country/ip/:ip

Given some IP(v4|v6) this responds with the proto message Country. Responds with a 400 Bad Request in case no mapping is found

  1. [GET] /country/iso/:iso

Given the ISO2 code, as defined in ISO 3166, of any country this route also responds with the proto message Country. 400 Bad Request if the code is not found.

  1. [GET] /city/:ip

Given some IP(v4|v6) this responds with the proto message City. 400 Bad Request if not found.

  1. [GET] /asn/:ip

Given some IP(v4|v6) this responds with the proto message ASN. 400 Bad Request if not found.