IP Lookup : Server Side vs Client Side
2 min readAug 30, 2019
ipapi is a service that helps you find the location of an IP address. Broadly speaking, there are 2 ways to use the service (REST API) :
Server Side
- In this case, your backend server communicates with our API endpoint.
- The IP address whose location has to be determined should be provided in the URL path.
- Syntax :
GET https://ipapi.co/{ip}/{format}/
:
- ip : IP address of your user
- format : json, csv, xml, yaml or jsonp - Suppose you have a client with IP address “8.8.8.8” that has made a request to your server. If your server wants to find the location of this client, you’ll send a request to the API (e.g. ipapi.co/8.8.8.8/json ). The response returns the location information for the IP in the URL path (i.e. 8.8.8.8)
- Once your server has access to this information, you can take further actions e.g. display the user’s city / country / currrency / timezone / weather etc.
- Server side API usage examples
- When to use server side API request:
- Your backend app needs the location for decision making
- You want to find the location even if the user has disabled Javascript
Client Side
- In this case, your user (the client) directly communicates with our API (e.g. with Javascript code embedded in your webpage or mobile app)
- You don’t need to provide the IP address of your user, we will infer it from the API call (and save you some work). This can be specially useful if you have a backend setup where you cannot readily access the IP address of your user. A request sent to ipapi.co/json directly from a client will magically return the location as well as the IP address of your user.
- Syntax :
GET https://ipapi.co/{format}/
:
- format : json, csv, xml, yaml or jsonp - Once your website / app has access to this information, you can take further actions e.g. display the user’s city / country / currrency / timezone / weather etc.
- Client side API usage examples
- When to use client side API request
- You want to get the location asynchronously with Javascript
- You don’t have access to the server or can’t modify the server code
- You don’t want to find the IP address of your user (we will do it for you).