Pyloid Docs
GithubLanguage
  • 💎What is Pyloid?
  • Getting Started
    • Prerequisites
    • Create Pyloid App
  • Core Concepts
    • Thread Safety
  • API
    • Python (Backend)
      • Pyloid
      • BrowserWindow
      • Monitor
      • TrayEvent
      • Utility Functions
      • RPC
      • Store
    • Javascript (Frontend)
      • Event
      • BaseAPI
      • RPC
  • Guides
    • Load Webview
    • Serve Frontend
    • Calling Python from JS
    • Calling JS from Python
    • Keyboard Shotcuts
    • Notification
    • Tray
    • Timer
    • File Watcher
    • Clipboard
    • Window Position
    • Devtools
    • Window Drag Region
    • Window Radius And Transparent
    • Autostart
    • Production Utils
    • Desktop Monitor
    • File Dialog
    • Splash Screen
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. API
  2. Javascript (Frontend)

RPC

PreviousBaseAPINextLoad Webview

Last updated 29 days ago

Was this helpful?

import { rpc } from 'pyloid-js';

// Call the 'greet' RPC function to receive a greeting.
rpc.call('greet', {name: 'Alice'})
  .then(response => {
    console.log(response); // Outputs "Hello, Alice!"
  })
  .catch(error => {
    console.error("Error occurred during RPC call:", error);
  });

This example demonstrates how to call the greet RPC function from the frontend, passing a name and receiving a greeting message. The rpc.call method is used to pass the function name and required parameters. If the call is successful, the response message is printed to the console, and if an error occurs, the error message is printed.

@rpc.method()
async def greet(name: str):
    return f"Hello, {name}!"

This is an example of the greet RPC function defined in Python. This function takes a name and returns a greeting message. You can call this function from the frontend to receive a greeting message.

more python rpc infomation