Java programming model
Cloud Functions provides four models for programming in Java: using the Function and YcFunction interfaces, the HttpServlet class, and the Spring Boot framework. The first three methods of setting a function handler involve writing their own implementations of these interfaces or classes, and the last one involves loading an application in its original form without any changes.
The difference between the Function and YcFunction models is in the presence of the invocation context. For example, if you need to work with Yandex Cloud services using the SDK, we recommend opting for YcFunction. With the HttpServlet class based model, you can get full control over the return value and HTTP
method used to call the function. Just as YcFunction
, it also provides access to the invocation context.
For the Function and YcFunction models, there are two separate types: byte[]
and String
. Using them is different from using other types. If you use them as the handler function argument type, the runtime environment will not convert the incoming request into a JSON
interpretation for these types and will deliver it directly to the user handler function, unless the ?integration=raw parameter is used.
Note
The library used for serialization and deserialization from JSON
is jsoniter
Handler requirements
Regardless of the selected model, a project is uploaded as a source code, a JAR archive, or a Maven project. In addition, the following requirements apply to a class that contains a handler function:
-
It must be public.
-
The class must have a public no-argument constructor.
It is included by default. However, if you created your own constructor that accepts arguments, you must also create a no-argument one.
-
It should not be generic
.