Apiipnet / apiip.net

The official JavaScript library for apiip.net that allowing customers to get location of IP address.
https://apiip.net
Apache License 2.0
4 stars 2 forks source link

Why response is cached #1

Closed aqlx86 closed 1 year ago

aqlx86 commented 1 year ago

Why is the response data for the user-agent cached? is there an option to turn this off?

I'm using a desktop browser but the response was from the initial request.

Screenshot 2023-09-05 at 10 43 49 PM
Apiipnet commented 1 year ago

Hello, the user agent response or any other response is not cached. Please use our API without the package if you need an accurate user-agent response, send the request from the browser. (https://apiip.net/documentation)

aqlx86 commented 1 year ago

same result. I skipped the packages

Screenshot 2023-09-05 at 11 23 01 PM
Apiipnet commented 1 year ago

Send the request via the browser, not from the server. We are taking user-agent from the request header. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent You can observe that if you send the request via Postman (https://www.postman.com) Or you can check by sending a request directly from the browser (browser's address bar) http://apiip.net/api/check?accessKey={key}

aqlx86 commented 1 year ago

So the code samples here capture the correct user-agent?

aqlx86 commented 1 year ago

Send the request via the browser, not from the server. We are taking user-agent from the request header. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent You can observe that if you send the request via Postman (https://www.postman.com) Or you can check by sending a request directly from the browser (browser's address bar) http://apiip.net/api/check?accessKey={key}

obviously, if you access the API URL directly in the browser it will capture the user-agent, but if you are integrating your API to another API you will need an HTTP client like Axios or fetch, The code snippet I posted above is the same in your examples it is inside of a API controller which is access in browser also.

Apiipnet commented 1 year ago

It is not about axios or fetch, it's about user-agent request header, so you can set it manually if you want, and it will work. You can check it here: https://apiip.net There you can find accurate userAgent response and we are using axios to make the request, but from the frontend side (client side), not from the server side, that is the difference. Any request will automatically attach a user-agent request header, so if you are making it from the backend side, it will capture your backend-server info, but if you are making the request from the client side, the user-agent will be the client's browser, device and OP. Also, you can set user-agent manually, first capturing the client's user-agent with your backend, and then setting the header when sending it to our API. It's up to you how you will implement it.