Using functions on Endpoints

Product: PowerShell Universal
Version: 5.6.7

I am starting to do some small developments using the Universal Powershell modules and I have some questions about endpoints.
Can functions be declared within the code itself?
This would help me simplify much of the code I want to implement in some endpoints.
I am also interested in knowing if it is possible to make REST requests from an app to the endpoints I have deployed to obtain data.