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. If, for example, you need to interact with Yandex.Cloud services using the SDK, we recommend that you choose YcFunction. The model based on the HttpServlet class lets you get full control over the return value and
HTTP method that was used to call the function and, like the
YcFunction model, grants access to the invocation context.
For the Function and YcFunction models, there are two separate types:
String. Using them is different from using other types. If you use them as the handler function argument type, the runtime doesn't convert an incoming request to a
JSON interpretation for these types and passes it directly to the user handler function. The exception is when the parameter integration=raw is used.
The library used for serialization and deserialization of
JSON is jsoniter.
Regardless of the selected model, a project is uploaded as a source code, or as a
jar archive, or as a
maven project. In addition, the following requirements apply to a class that contains a handler function:
- It must be public.
- It must have a public constructor with no arguments.
By default, it is present. But if you created your own constructor that accepts arguments, you should also create a constructor that doesn't accept any arguments.
- It shouldn't be generic.