使用 Ruby 或 Python 等语言与 API 交互
我希望开始构建网络应用程序。我需要基本的 CRUD 功能。
我了解如何在 ruby 和 python 中执行此操作的基础知识 - 但这就是我陷入困境的地方:
How do I parse a GET or POST request in Ruby/Python?
我正在尝试与其他人的 API 进行交互,我知道我需要的字符串,只是不知道如何在编码时引用和使用该字符串。
例子: 我想引用用户个人资料,并计算他们发布的帖子数量。
我知道 URL 看起来像这样: http://www.coolwebsite.com/users?bobsgreat?postcount
返回一个value= 他的帖子。
如何将这个数字放入我的 Python 脚本中,然后如何让 Python 将其写入 HTML 文件中以供查看?
抱歉,如果我在这里问了很多问题,随着我开始写作,这个问题也越来越多。
I'm looking to start building web apps. I need basic CRUD functionality.
I understand the basics of how to do this in ruby and python - but here's where I'm stuck:
How do I parse a GET or POST request in Ruby/Python?
I'm trying to interact with someone else's API, I know the string I need, just not how to reference and use that string while coding.
Example:
I want to reference a users profile, and count the number of posts they've made.
I know the URL looks something like this:
http://www.coolwebsite.com/users?bobsgreat?postcount
That returns a value= to his posts.
How do I get this number into my Python script- and then how can I have python write this into an HTML file for viewing?
Sorry if I'm asking a lot here, the question grew as I started writing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个非常粗略的示例,说明如何在 python 中执行此操作。它需要根据您的具体情况进行修改,但希望它可以帮助您开始:
This is a very rough example of how you can do this in python. It would need modification for your specific situation, but hopefully it can get you started:
如果您必须处理 API 并使用 Ruby,我强烈推荐 api_smith gem。上次我不得不这样做时,我花了大约 2 个小时左右的时间来完成整个 API。以下博客文章提供了很好的介绍:
构建使用 API Smith 构建结构化 API 客户端
If you have to deal with an API and use Ruby, I highly recommend the api_smith gem. Last time I had to do it it took me like 2 hours or so to wrap up an entire API. The following blog post gives a good introduction:
Building Structured API Clients with API Smith