GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing nullstack.app — Server Functions - Nullstack Server FunctionsServer functions are specialized microservices that at transpile time are converted into API entry points. To flag a function as a server function, you must declare it as Being a static function means it has no access to the instance scope. However, instead of calling the static version from the class, you must invoke it as an instance function. Server functions can be called anytime in your code and are not limited to prerender steps.
You can also call static methods directly which is useful for some code patterns that invoke external server functions.
Client behaviorWhen you call a server function from the client, the arguments will be serialized as JSON. The arguments will be posted against the automatically generated API and merged with the server context when it reaches the server. The return value of the server function will be serialized back to the client and can be seamlessly used as if it were a local function.
Server behaviorServer functions will be used as local functions, simply aliasing the instance call to the class and merging the arguments with the server context. Date ConvenienceDates are serialized as UTC in JSON and deserialized back to
Fetch Convenience
Server only importsImported dependencies that are only used inside server functions will be excluded from the client bundle. This is useful for both accessing node.js exclusive modules and reducing the client bundle size by preprocessing data like markdown without having to expose the dependency to the end-user.
SecurityKeep in mind that every server function is similar to an Express route in API and must be coded without depending on view logic for security.
Server functions with the name starting with "_" do not generate an API endpoint and do not have access to the context by default to avoid malicious API calls.
Reserved wordsServer function names cannot collide with instance method names from the current class or its parent classes. The following words cannot be used in server functions:
Server functions named Reserved HTTP method prefixesServer functions declared with their names starting with HTTP verbs will be executed accordingly to the respective HTTP method. Supported verbs are:
Performance ConsiderationsServer functions are just API endpoints in the end of the day. Be mindful of this when making function calls, and try to keep the payload as small as possible.
CaveatsAutomatically generated API endpoints are not meant to be used by 3rd-party apps. The URL and implementation may change between versions of Nullstack. Server functions endpoints are based on file path and function name, changing those might cause backwards compatibility problems in some scenarios.
Next Step➡️ Learn more about Core Features: Context❓ Have any questions or suggestions? Join our Discord |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |