-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
34 lines (25 loc) · 1.08 KB
/
main.py
File metadata and controls
34 lines (25 loc) · 1.08 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
from crowdstrike.foundry.function import Function, Request, Response, APIError
func = Function.instance()
# Handler hello
@func.handler(method='POST', path='/hello')
def on_post(request: Request) -> Response:
#
# 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()