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

查看:78
本文介绍了适用于我的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或任何其他Framework一起使用,那就太好了.我正在运行Nginx.

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

NB:我在这里的旧问题,我知道我应该从Googling和Googling那里获取,我必须将其转换为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天全站免登陆