光标必须位于定义正下方的行上,以生成完全自动填充的文档字符串
Better Comments扩展将帮助您在代码中创建更加人性化的注释。
有了这个扩展,您将能够将您的注释分类为:
REST客户端允许您直接在Visual Studio Code中发送HTTP请求并查看响应。
主要功能
GET http://example.com HTTP/1.1
点击代码头上的 Send Request 就可以发送网页请求,右侧就是response
以### 分割上个请求
###
GET http://httpbin.org/json HTTP/1.1
###
POST http://httpbin.org/post HTTP/1.1
x-my-name: zgpeace
{
"arg1" : "value1"
}
可以看到header 是 zgpeace, body设置 value1,点击右上角还可以保存response数据
选择需要生成的代码,右键 Generate Code Snippet
可以生成的语言列表Go, Java, Python, C, Swift… 这里选择Python
选择http.client lib
import http.client
conn = http.client.HTTPConnection("httpbin.org")
payload = "{\"arg1\" : \"value1\"}"
headers = {
'user-agent': "vscode-restclient",
'x-my-name': "zgpeace"
}
conn.request("POST", "/post", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
运行结果如下
(.venv) 17:04:15 zgpeace@zgpeaces-MacBook-Pro.local langchain-llm-app develop ? python HTTP/TestPost.py
{
"args": {},
"data": "{\"arg1\" : \"value1\"}",
"files": {},
"form": {},
"headers": {
"Accept-Encoding": "identity",
"Content-Length": "19",
"Host": "httpbin.org",
"User-Agent": "vscode-restclient",
"X-Amzn-Trace-Id": "Root=1-6583ff96-5783744b06279eb675fc4ad9",
"X-My-Name": "zgpeace"
},
"json": {
"arg1": "value1"
},
"origin": "61.140.244.138",
"url": "http://httpbin.org/post"
}
https://github.com/zgpeace/pets-name-langchain/tree/develop