如何解决如何为 url 构建路径和响应对象
我想为以下网址创建路径对象
url: "http://127.0.0.1:5000"
在代码中,当用户输入上面提到的 url 后跟斜杠 \ 一个名为 start() 的方法将被调用和执行。 调用该方法时,它会以 json 文件的形式接收来自后端的响应并将其返回。
请如何为此类操作构建路径和响应对象
代码:
@app.route("/",methods=['GET','POST'] )
def startCoord2():
baseURL = "https://api.openrouteservice.org/v2/directions/driving-car?api_key=5b3ce3597851110001cf62480ecf8c403567479a87de01df5da651fb&start=8.681436,49.414554&end=8.681561,49.414747"
with urllib.request.urlopen(baseURL) as response:
print ("str(response): " + str(response))
print ("str(response.getCode(): " + str(response.getcode()))
data = response.read()
print ("response.read(): " + str(data))
dataAsJSONObject = json.loads(data)
distance = str(dataAsJSONObject["features"][0]['properties']['segments'][0]['distance'])
return dataAsJSONObject #config['EndPoint']['url'] + config['EndPoint']['api_key'] + "&start=" + startLat + "," + startLng + "&end=" + end1Lat + "," + endLng + ""
yaml 文件:
openapi: '3.0.2'
info:
title: &apiTitle "Distance micro-service API."
description: "This micro-service receives four comma separated GPS coordinates in the following order,startLongitude,startLatitude,endLongitude,endLatitude in the url. Then it receives a response in a form of json file. The json file is to be fetched for the distance which represents the distance between
the aforementioned GPS coordinates"
version: '1.0'
termsOfService: "http://127.0.0.1:5000/getDistance/terms"
contact:
name: " "
url: "http://127.0.0.1:5000"
email: "me@provider.com"
license:
name: "CC Attribution-ShareAlike 4.0 (CC BY-SA 4.0)"
url: "https://openweathermap.org/price"
servers:
- url: http://127.0.0.1:5000
description: Local host test server. When accessed it will return the distance from Berlin to Alexandria in Egypt in kilometers.
variables:
originAndDestinationGPSCoords:
default: 13.404954,52.520008,29.924526,31.205753
description:
Local host test server. When accessed it will return the distance from Berlin to Alexandria in Egypt in kilometers.
paths:
/:
get:
tags:
- "get response data in json format"
summary:
get the distance between 8.681436,49.414554,8.681561,49.414747
description: >
to display data in json formate
responses:
'200':
description: Distance fetched successfully.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。