3

I have a few custom REST API interfaces on my module & they all need to return a standard json response (different on each).
After a little research, I realized that I can't do something like @return object & that echo json_encode($res);die; is discouraged & that I can build a custom data interface with a getter method for every field.
For my specific needs, it'll require very long files with tons of getter methods (I have to return a specific structure of fields as json).


Is there a way to build this data interface without creating a method for every field in the response?
e.g. something that I can load with an array/object or even a json encoded string & it'll just reply with that without any change.
*I know that I can return json_encode(...); & define the return type as a string, but it's wrapping it with quotes ("{...}") & escapes & I don't want it that way.
-- Any Idea?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.