-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
42 lines (32 loc) · 1.33 KB
/
main.py
File metadata and controls
42 lines (32 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""Main module for the hello function handler."""
from crowdstrike.foundry.function import Function, Request, Response, APIError
FUNC = Function.instance()
@FUNC.handler(method="POST", path="/hello")
def on_post(request: Request) -> Response:
"""
Handle POST requests to /hello endpoint.
Args:
request: The incoming request object containing the request body.
Returns:
Response: JSON response with greeting or error message.
"""
#
# Replace the following example code with your handler code
#
# Demonstrates how to validate the request body if your handler requires input payload
# Replace with your own request and update the request_schema.json to match
if "name" not in request.body:
# This example expects "name" field in the request body and returns
# an error response (400 - Bad Request) if not provided by the caller
return Response(
code=400,
errors=[APIError(code=400, message="missing name from request body")]
)
# Demonstrates how to return a success response with JSON body
# Replace with your response and update the response_schema.json to match
return Response(
body={"greeting": f"Hello {request.body['name']}! It is nice to see you."},
code=200,
)
if __name__ == "__main__":
FUNC.run()