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 choosing YcFunction. The model based on the HttpServlet class lets you get full control over the return value and HTTP
method, which was used to call the function. Like the YcFunction
model, it grants 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 does not convert an incoming request to a JSON
interpretation for these types and delivers it directly to the user handler function. The exception is when the parameter ?integration=raw.
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, 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
.