Call init function inside REST service function

In CF10, the new operator calls init implicitly, and we should not call it explicitly when creating the object.

But what happens if I have a REST service with an init method; properties defined in init become available inside any REST resource?

My tests show that they do not. Ultimately, calling REST calls a function, and I believe that every call to an implicit function leads to the creation of an object behind the scenes.

Is REST different from creating / creating an object of a normal object? Is it possible to create init (it can be, but it is an effective / good practice)?

+5
source share
1 answer

I'm just starting to be more attentive to REST. One thing that I will point out is that REST is stateless. See the description of wikipedia . Each request costs one, the client must maintain any state that is necessary, and transmit it using the request. The service simply responds to requests. I would say that having init () in a RESTful service is neither good nor bad practice. This can be a convenient place to collect function calls and variables that you usually use during queries. Then, when you pass your state with the request, this method can then call init (), and then continue its business.

0
source

Source: https://habr.com/ru/post/1200829/


All Articles