Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invoke init function inside a REST service function

In CF10 the new operator calls init implicitly and we need not call it explicitly while creating an object.

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

My tests shows they do not. Ultimately the REST call is invoking a function and I believe that each implicit function invocation results in object creation behind the scenes.

Is REST different than normal object creation/instantiation? Can an init even be created (it can be, but is it a workable/good practice)?

like image 474
CFML_Developer Avatar asked Nov 11 '22 03:11

CFML_Developer


1 Answers

I'm just beginning to look more closely at REST. One thing that I will point out is that REST is stateless. Take a look at the wikipedia description. Each request stands alone, the client should maintain any state that is necessary, and pass that in with the request. The service just responds to requests. I'd say that having an init() in your RESTful service is neither a good nor a bad practice. It might be a handy place to collect function calls and variable settings that you would commonly use during requests. Then when you pass your state in with a request, that method could then call the init(), then go on about its business.

like image 174
Barry Avatar answered Nov 15 '22 12:11

Barry