Skip to content

Commit 8b8adcd

Browse files
authored
add comments to sample code
1 parent 06bbb29 commit 8b8adcd

File tree

1 file changed

+55
-1
lines changed
  • helloworld-samples/function-codebundle-python

1 file changed

+55
-1
lines changed
Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,66 @@
1-
from lorem_text import lorem
1+
# ======================================================= #
2+
# IBM Cloud Code Engine - Functions-as-a-Service Sample #
3+
# #
4+
# __main.py__ (Python sample function) #
5+
# #
6+
# This sample code uses an external module "lorem" #
7+
# to generate an arbitrary result message. IBM code #
8+
# engine functions code with references to external #
9+
# modules have to be deployed as code-bundles. #
10+
#
11+
# This sample shows how to access URL parameters in a #
12+
# function. #
13+
# #
14+
# This sample shows how an external reference is coded #
15+
# in the source file (__main__.py) and how the modul #
16+
# is referenced in the requirements.txt. #
17+
# #
18+
# ======================================================= #
219

20+
##
21+
# import the referenced "lorem" module
22+
from lorem_text import lorem
323

24+
##
25+
# The `main` function is the entry-point into the function.
26+
#
27+
# A function can define multiple functions, but it needs to
28+
# have one dedicated 'main' function, which will be called
29+
# by the runtime.
30+
#
31+
# The 'main' function has one optional argument, which
32+
# carries all the parameters the function was invoked with.
33+
#
34+
# Those arguments are dynamic and can change between
35+
# function invocations.
36+
#
37+
# Additionally, a function has access to some
38+
# predefined and also user-defined environment variables.
39+
#
440
def main(params):
541
words = 10
642

743
return {
44+
# specify headers for the HTTP response
45+
# we only set the Content-Type in this case, to
46+
# ensure the text is properly displayed in the browser
847
"headers": {
948
"Content-Type": "text/plain;charset=utf-8",
1049
},
50+
51+
## use the text generator to create a response sentence
52+
# with 10 words
1153
"body": lorem.words(words),
1254
}
55+
# Optional:
56+
# If you used a function name different from 'main', make
57+
# the function known under the 'main' symbol to the
58+
# runtime, so it can be invoked.
59+
#
60+
# Example:
61+
#
62+
# def my_main_func_with_another_name(params) {
63+
# ...
64+
# }
65+
# ...
66+
# main = my_main_func_with_another_name

0 commit comments

Comments
 (0)