2

I have a script on python, which prints some data. The script is on Centos7, nginx.

How could I connect to the script via URL (GET query) to be able to parse the data?

1
  • 1
    You will have to create a RESTful webservice (eg. with flask, there are many tutorials online just google for flask restful) Commented Mar 11, 2018 at 19:00

1 Answer 1

1

You can use a framework like Django or flask to make an api out of it. I'll suggest flask since it's very light-weight, making it ideal for such small tasks.

E.g.

def your_function(input):
    # do something
    return output


from flask import Flask
from flask import request

app = Flask(__name__)

@app.route('/my_api')
def your_api_function():
    input = request.args.get('my_query_string')
    return your_function(input)

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

And then use the endpoint

/my_api?my_query_string=my_input

You can further play around with it to return JSON, take parameters from request body and so on and so forth.

Read more here http://flask.pocoo.org/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.