与我的 python 程序而不是数据库一起使用的 REST API 框架 [英] REST API framework that works with my python program instead of Database

查看:29
本文介绍了与我的 python 程序而不是数据库一起使用的 REST API 框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个非常简单的 REST API.我发现 EVE 框架非常有前途,我想而不是使用数据库.导入我的 .py 代码并执行它并返回字符串.它应该是这样的:

I wanted to create a very simple REST API. I found EVE Framework very promising and I want to instead of using a Database. import my .py code and execute it and return the string. It should be something like:

http://myipserver:5000/myprogram.py?string=xxx

其中 'xxx' 是我要获取的字符串,然后使用我的 .py 代码对其进行评估.

where 'xxx' is the string I'm looking to get and then evaluate it using my .py code.

如果有办法让它与 EVE 或任何其他框架一起工作,那就太好了.我正在运行 Nginx.

It'd be great if there's a way to make it work with EVE or any other Framework. I'm running Nginx.

注意:我的老问题,我知道我应该从谷歌搜索和谷歌搜索,我必须将它转换为 PHP 或另一种在 Linux 上运行的编程语言,所以我选择了 Python,因为我已经熟悉它.现在我想将它作为 REST API 运行,而不仅仅是 Socket/TCP 简单服务器.

NB: my old question here, I understand that I should from Googling and Googling that I have to convert it to PHP or another programming language that runs on Linux so, I chose Python since I'm already familiar with it. and now I want to run it as REST API instead of just Socket/TCP simple server.

推荐答案

如果我的问题是对的,您可以在 Eve REST API 之上安装自定义端点.不久前我写了一篇关于这个的文章,看看对于细节,但它实际上归结为做这样的事情:

If I got your question right yes, you can mount custom endpoints on top of a Eve REST API. Not a long ago I wrote an article about this, check it out for the details, but it really boils down to doing something like this:

from eve import Eve
app = Eve()

@app.route('/hello')
def hello_world():
    return 'Hello World!'

if __name__ == '__main__':
    app.run()

这只是利用了标准的 Flask 功能.然后您可以访问 /hello 端点,您的函数将在该端点执行任何需要执行的操作.

This is just leveraging the standard Flask features. Then you can access the /hello endpoint where your function will do whatever it needs to do.

这篇关于与我的 python 程序而不是数据库一起使用的 REST API 框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆