Soumil Nitin Shah
Soumil Nitin Shah

Reputation: 730

Calling Flask route internally with requests

I am trying to call one internal route through another Flask route. Essentially I want to develop a mini internal microservice.

try:
    import json
    import os
    import sys
    from flask import Flask
    from flask import app
    import requests
    from flask import Flask, redirect, url_for

except Exception as e:
    print("Error : {} ".format(e))

app = Flask(__name__)


@app.route('/call1', methods=["GET", "POST"])
def m_call1():
    return "call1"


@app.route('/call2', methods=["GET", "POST"])
def call2():
    res = requests.get('call1/')
    print(res.json())
    return "call2" + res.json()


if __name__ == "__main__":
    app.run(host='0.0.0.0', port=5000, debug=True, threaded=True)

Upvotes: 0

Views: 968

Answers (1)

Divyessh
Divyessh

Reputation: 2721

Although it is not suggested to do this but if you need to do so

You can try : make a config.py and type in :

DOMAIN = ""

in your main file

from config import *
res = requests.get(f'{DOMAIN}/call1/')

Upvotes: 1

Related Questions