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.

    评论

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了