0

I am rewriting a PHP app to a Azure Static Web App and struggeling with some API functionality. In the old PHP Site, there are few AJAX API Calls and the API is using $_SERVER['REMOTE_ADDR'] to get the client IP.

I know in flask was that functionality flask.request.remote_addr. Is there anything in azure.functions where I currently basically the HttpRequest and HttpResponse classes and seek a easy way to get the client IP.

Any advise is welcome!

Joe Platano
  • 586
  • 1
  • 14
  • 27
  • 1
    Seems like this is possible only if the the function app is using [App Service Authentication / Authorization](https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-http-webhook-trigger?tabs=python#working-with-client-identities) – Abdul Niyas P M Nov 01 '21 at 10:08
  • unfortunately the API usage will be anonym. Maybe I will switch to flask instead of azure.functions.httprequest/response – Joe Platano Nov 01 '21 at 11:35

1 Answers1

0

In Azure functions you can use Http trigger for Http request to get the IP. Else in python we can get it as below:

import logging

import azure.functions as func

def main(req: func.HttpRequest) -> func.HttpResponse:

    category = req.route_params.get('category')
    id = req.route_params.get('id')
    message = f"Category: {category}, ID: {id}"

    return func.HttpResponse(message)

Check for attributes and annotations from MS Docs

SaiKarri-MT
  • 1,174
  • 1
  • 3
  • 8