Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@push-rpc/http

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@push-rpc/http

HTTP transport for Push-RPC.

  • 1.9.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

HTTP transport for Push-RPC.

Server-side push is not supported, only client-initiated messages are enabled.

Integrates with Koa or Express for HTTP server. Uses Fetch for making HTTP requests.

How to use (with Koa)

import * as Koa from "koa"
import {createRpcServer, createRpcClient} from "@push-rpc/core"
import {createKoaHttpServer, createHttpClient} from "@push-rpc/http"

...

/* server part */
const services = {
  async getHello() {
    return "Hello from Server"
  },
}

// remote id is required for assigning separate HTTP requests to a single session 
function getRemoteId(ctx: Koa.Context) {
  return "1" // share a single session for now, real impl could use cookies or some other meaning for HTTP sessions
}

createRpcServer(services, createKoaHttpServer(5555, getRemoteId))

...

/* client part */
const {remote} = await createRpcClient(0, () => createHttpClient("http://localhost:5555"))
console.log("From server: " + (await remote.getHello()))

Mapping between Push-RPC protocol and HTTP

All requests and responses are JSON-encoded.

Request path specifies operation to be invoked or topic to be queried. Path is static, no parameters is path are supported. Use request body instead to send parameters.

Query string parameters are not used.

When error is returned from the server, response is 400, response status string contains error message, response body contains error details in JSON-format.

Push-RPC Message TypeHTTP VerbDescription
CALLPOST Calls a remote method. POST body is request object, response body is response object.
GETPUT Query topic once for a data. POST body is query parameters, response body is response object.
SUBSCRIBEPATCH Subscribe topic for a data, but server will return them only once. Behaves the same as GET type. POST body is query parameters, response body is response object.

FAQs

Package last updated on 06 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc