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 invocation context that is either available or not. For example, if you need to work with Yandex Cloud services using the SDK, we recommend choosing YcFunction. Meanwhile, the model based on the HttpServlet class allows you to 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 an incoming request to a JSON
interpretation for these types and will deliver it directly to the user handler function, unless you use the ?integration=raw parameter.
Note
The library used for serialization and deserialization of 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
.