passing-notes-rpc

    1.1.2 • Public • Published

    passing-notes-rpc

    npm CI Status dependencies Status devDependencies Status

    Simple communication between browser and server

    Usage

    Install passing-notes-rpc by running:

    yarn add passing-notes-rpc

    Then, compose it with other middleware:

    import {compose, Logger} from 'passing-notes'
    import {serveRpc} from 'passing-notes-rpc'
    import serveUi from 'passing-notes-ui'
    
    const logger = new Logger()
    
    export default compose(
      serveRpc({
        logger,
        actions: {
          echo(text) {
            return `echo: ${text}`
          }
        }
      }),
      serveUi({path: './ui', logger}),
      () => () => ({status: 404})
    )

    These actions can then be called in the browser:

    // ui/index.html
    <!doctype html>
    <meta charset="utf-8">
    <script type="module" src="/index.js"></script>
    // ui/index.js
    import {makeRpcClient} from 'passing-notes-rpc'
    
    const client = makeRpcClient()
    
    async function run() {
      const result = await client.echo('Hello!')
      console.log(result) // 'echo: Hello!'
    }
    
    run()

    Keywords

    none

    Install

    npm i passing-notes-rpc

    DownloadsWeekly Downloads

    11

    Version

    1.1.2

    License

    MIT

    Unpacked Size

    5.47 kB

    Total Files

    6

    Last publish

    Collaborators

    • vinsonchuong