REST API framework that works with my python program instead of Database

浪尽此生 提交于 2019-12-11 10:00:04

问题


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

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

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

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.


回答1:


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()

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.



来源:https://stackoverflow.com/questions/32614751/rest-api-framework-that-works-with-my-python-program-instead-of-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!