Skip to content

Commit bcfba4d

Browse files
authored
Merge pull request #5 from paulyuk/hotfix/get-code
Simplifying GET logic and allowing null name param like other samples
2 parents e4ca422 + 16af044 commit bcfba4d

File tree

2 files changed

+7
-19
lines changed

2 files changed

+7
-19
lines changed

README.md

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pip install -r requirements.txt
6060
func start
6161
```
6262

63-
2) Test the HTTP GET trigger using the browser to open [http://localhost:7071/api/httpGetFunction](http://localhost:7071/api/http_get)
63+
2) Test the HTTP GET trigger using the browser to open [http://localhost:7071/api/http_get](http://localhost:7071/api/http_get)
6464

6565
3) Test the HTTP POST trigger in a new terminal window:
6666
```bash
@@ -82,17 +82,11 @@ The key code that makes tthese functions work is in `function_app.py`. The func
8282
```python
8383
@app.route(route="http_get", methods=["GET"])
8484
def http_get(req: func.HttpRequest) -> func.HttpResponse:
85-
name = req.params.get("name")
86-
85+
name = req.params.get("name", "World")
86+
8787
logging.info(f"Processing GET request. Name: {name}")
8888
89-
if name:
90-
return func.HttpResponse(f"Hello, {name}!")
91-
else:
92-
return func.HttpResponse(
93-
"Please pass a 'name' parameter in the query string",
94-
status_code=400
95-
)
89+
return func.HttpResponse(f"Hello, {name}!")
9690
```
9791
This code shows a HTTP POST triggered function.
9892

function_app.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,11 @@
55

66
@app.route(route="http_get", methods=["GET"])
77
def http_get(req: func.HttpRequest) -> func.HttpResponse:
8-
name = req.params.get("name")
9-
8+
name = req.params.get("name", "World")
9+
1010
logging.info(f"Processing GET request. Name: {name}")
1111

12-
if name:
13-
return func.HttpResponse(f"Hello, {name}!")
14-
else:
15-
return func.HttpResponse(
16-
"Please pass a 'name' parameter in the query string",
17-
status_code=400
18-
)
12+
return func.HttpResponse(f"Hello, {name}!")
1913

2014
@app.route(route="http_post", methods=["POST"])
2115
def http_post(req: func.HttpRequest) -> func.HttpResponse:

0 commit comments

Comments
 (0)