英文:
Calling a GET REST API in golang with a path variable
问题
我第一次尝试使用Golang。我正在尝试调用一个带有路径变量的GET REST API。我正在使用net/http库。我尝试了下面的代码,但是到目前为止没有成功。我想知道如何使用路径变量并从代码中传递变量。非常感谢任何帮助或代码示例。
这段代码似乎不起作用:
http.Get("http://127.19.0.1:8080/student/:id")
英文:
I am trying Golang for the first time. I am trying to call a GET REST API which has a path variable. I am using net/http for that. I am trying like below but no luck so far. I need to know how I can use the path variable and pass the variable from the code. Any help or code example would be highly appreciated.
This does not seem to work:
http.Get("http://127.19.0.1:8080/student/:id")
答案1
得分: 3
关于这个问题的翻译如下:
http.Get(fmt.Sprintf("http://127.19.0.1:8080/student/%s", id)
是什么意思?
英文:
what about
http.Get(fmt.Sprintf("http://127.19.0.1:8080/student/%s", id)
?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论