git - Running an executable on Heroku upon Flask API endpoint access - TagMerge
3Running an executable on Heroku upon Flask API endpoint accessRunning an executable on Heroku upon Flask API endpoint access

Running an executable on Heroku upon Flask API endpoint access

Asked 1 years ago
0
3 answers

Git tracks the executable bit of files. You should be able to make the file executable locally, then commit and redeploy:

chmod +x <executable>
git add <executable>
git commit -m "Set executable bit on <executable>"
git push heroku

Though if it is available via an Ubuntu package you'll be better served by not tracking it at all and installing it via the Apt buildpack.

There may be other options as well, but without more information about what <executable> is and where it comes from it's hard to suggest the right solution.

Source: link

0

After installation login into the Heroku Cli by running this command in the terminal.
heroku login
Let us start by cloning the application. Open the terminal and paste in this command to clone the application. A gentle reminder that this step will only work if you have Git installed on your computer.
git clone https://github.com/jokamjohn/bucket_api_heroku.git
Open the folder bucket_api_heroku with your favorite text editor or IDE. Create a virtual environment and install the dependencies by running.
pip install -r requirements.txt
Before we can add a Procfile, we need to first install a web server called Gunicorn. Run the following command within the application folder.
pip install gunicorn
Update the requirements file by running
pip freeze > requirements.txt

Source: link

0

In your project directory, let's start off by creating a virtualenv:
$ python -m venv venv/
And let's activate it with the source command:
$ source venv/bin/activate
Then, let's use pip to install the libraries we're going to use - flask to build the app and gunicorn as our server:
$ pip install flask
$ pip install gunicorn
Our application is going to be a simple API that receives a name and returns a welcome message:
# app.py
from flask import Flask, request, jsonify
app = Flask(__name__)

@app.route('/getmsg/', methods=['GET'])
def respond():
    # Retrieve the name from url parameter
    name = request.args.get("name", None)

    # For debugging
    print(f"got name {name}")

    response = {}

    # Check if user sent a name at all
    if not name:
        response["ERROR"] = "no name found, please send a name."
    # Check if the user entered a number not a name
    elif str(name).isdigit():
        response["ERROR"] = "name can't be numeric."
    # Now the user entered a valid name
    else:
        response["MESSAGE"] = f"Welcome {name} to our awesome platform!!"

    # Return the response in json format
    return jsonify(response)

@app.route('/post/', methods=['POST'])
def post_something():
    param = request.form.get('name')
    print(param)
    # You can add the test cases you made in the previous function, but in our case here you are just testing the POST functionality
    if param:
        return jsonify({
            "Message": f"Welcome {name} to our awesome platform!!",
            # Add this option to distinct the POST request
            "METHOD" : "POST"
        })
    else:
        return jsonify({
            "ERROR": "no name found, please send a name."
        })

# A welcome message to test our server
@app.route('/')
def index():
    return "<h1>Welcome to our server !!</h1>"

if __name__ == '__main__':
    # Threaded option to enable multiple instances for multiple user access support
    app.run(threaded=True, port=5000)
We can also send a name as a parameter, such as http://localhost:5000/getmsg/?name=Mark:
{"MESSAGE":"Welcome Mark to our awesome platform!!"}

Source: link

Recent Questions on git

    Programming Languages