4

I'm playing with Azure Functions and the main method is

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

Can someone please break down every part of this and explain what it means. Specifically what does req: func.HttpRequest mean, is it forcing some data type for the parameter? And what does -> func.HttpResponse mean, is it forcing a return type?

I've never seen this syntax in Python before.

Nic
  • 637
  • 2
  • 6
  • 19
  • 5
    The phrase you should Google is: Python Annotations – dfundako Nov 12 '19 at 21:39
  • 2
    You are seeing annotations and type hinting. `req` is a required positional argument. `: func.HttpRequest` is a type hint telling the user what `req` should be. In this case an HTTP request object. The trailing bit `-> func.HttpResponse` is another annotation telling you what the function returns. In this case an HTTP Response object. – James Nov 12 '19 at 21:39
  • 1
    [Typing](https://docs.python.org/3/library/typing.html) – Cory Kramer Nov 12 '19 at 21:40

1 Answers1

4

It defines a function named main, which takes one parameter named req that is of type func.HttpRequest, and returns a value of type func.HttpResponse.

John Gordon
  • 29,573
  • 7
  • 33
  • 58