weixin_33725270 2017-10-31 14:13 采纳率: 0%
浏览 254

API中的端点是什么

I have the following description of an API. How do I call this API in my react app or through postman? I don't understand the endpoints in it.

Deployed a CORS-enabled API for IP geolocation and weather lookup at

https://weathersync.herokuapp.com. 

There are two endpoints:

/ip

Get the geographic location of the requestor’s IP

/weather/$lat,$lng

Get weather for a given latitude & longitude

I tried https://weathersync.herokuapp.com/weather/28.704059,77.102490 in postman but it doesn't work. Also, https://weathersync.herokuapp.com/?ip=192.168.0.106 doesn't work. Any help is appreciated aI i am new to APIs

  • 写回答

1条回答 默认 最新

  • weixin_33728268 2017-10-31 15:11
    关注

    Through simple trial and error I managed to determine that this API expects you to call it like this for the /ip route:

    https://weathersync.herokuapp.com/ip?73.119.54.218

    Note that this is pretty unusual and would be considered incorrect by most API designers. I would expect it to be /ip/73.119.54.218 instead, but the server is not set up correctly to handle that.

    Also, as TKoL mentioned in the comments, an IP like 192... will never work, because it is a local IP address that is not visible to the outside world beyond your network. If the server attempts to lookup anything based on that IP address, it will likely not find anything, or even worse it might find something about a computer inside of its datacenter, in which case it could return data that is subtly incorrect from your point of view. You can find your external IP with services like iplocation.net.

    Your weather example works fine for me as-is (try clicking below in a browser):

    https://weathersync.herokuapp.com/weather/28.704059,77.102490

    I did not try Postman, but it may not be working for you because it does not send the same HTTP headers as a browser does. Some servers expect certain headers to be sent. You can manually configure the headers in Postman to mimic a browser, which should work if that is the case.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小游戏反编译后,出现找不到分包的情况
  • ¥15 如何实现从tello无人机上获取实时传输的视频流,然后将获取的视频通过yolov5进行检测
  • ¥15 WPF使用Canvas绘制矢量图问题
  • ¥15 用三极管设计一个单管共射放大电路
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥15 LCD12864中文显示