-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
19 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,25 @@ | ||
''' | ||
import azure.functions as func | ||
import requests | ||
import os | ||
app = func.FunctionApp() | ||
@app.function_name(name="SpotBotTrigger") | ||
@app.route(route="hello", auth_level=func.AuthLevel.ANONYMOUS, methods=["POST"]) | ||
def main(req: func.HttpRequest) -> func.HttpResponse: | ||
content = req.get_json() | ||
target_url = os.getenv('TARGET_URL') | ||
if not target_url: | ||
return func.HttpResponse("Error: TARGET_URL environment variable is not set.", status_code=500) | ||
response = requests.post(target_url, json=content) | ||
return func.HttpResponse(response.text, status_code=response.status_code) | ||
''' | ||
|
||
import azure.functions as func | ||
import logging | ||
|
||
app = func.FunctionApp() | ||
app = func.FunctionApp(http_auth_level=func.AuthLevel.FUNCTION) | ||
|
||
@app.function_name(name="HttpTrigger1") | ||
@app.route(route="hello", auth_level=func.AuthLevel.ANONYMOUS) | ||
def test_function(req: func.HttpRequest) -> func.HttpResponse: | ||
@app.route(route="http_trigger1") | ||
def http_trigger1(req: func.HttpRequest) -> func.HttpResponse: | ||
logging.info('Python HTTP trigger function processed a request.') | ||
return func.HttpResponse( | ||
"This HTTP triggered function executed successfully.", | ||
status_code=200 | ||
|
||
name = req.params.get('name') | ||
if not name: | ||
try: | ||
req_body = req.get_json() | ||
except ValueError: | ||
pass | ||
else: | ||
name = req_body.get('name') | ||
|
||
if name: | ||
return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.") | ||
else: | ||
return func.HttpResponse( | ||
"This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.", | ||
status_code=200 | ||
) |