![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
github.com/rpcx-ecosystem/rpcx-gateway
rpcx-gateway is a http gateway for rpcx services.
rpcx is a fast rpc framework. Faster, more features.
You can write rpc http clients in any programming languages such as Java、Python、C#、Node.js、Php、C\C++、Rust and others. See examples
There are two deployment modes: Gateway and Agent。
You can deploy this as gateway model. Gateway is running at independent servers. Clients sends http requests to gateways, and gateways translate http requests into raw rpcx requests. And then gateways send raw rpcx requests to rpcx services.
when gateways receive rpcx responses, they translates rpcx responses into http responses and return clients.
You can scale gateway easily because it is stateless.
It works like a http load balancer.
You can also deploy this as agent model. Agents are deploy with clients. They are installed as a daemon application in node of clients. If there are multiple clients in one node, you only need to install one agent.
Clients send http requests to their local agent. The local agent translate http requests into rpcx requests, send rpcx requests to rpcx services, translate rpcx responses into http ressponses.
It works like service mesh.
You can send a http request in any programming languages. You must set some extra http headers in requests.
For the http response, there are some extra http headers:
There is a golang http client example:
package main
import (
"bytes"
"io/ioutil"
"log"
"net/http"
"github.com/rpcxio/rpcx-gateway"
"github.com/smallnest/rpcx/codec"
)
type Args struct {
A int
B int
}
type Reply struct {
C int
}
func main() {
cc := &codec.MsgpackCodec{}
// request
args := &Args{
A: 10,
B: 20,
}
data, _ := cc.Encode(args)
req, err := http.NewRequest("POST", "http://127.0.0.1:9981/", bytes.NewReader(data))
if err != nil {
log.Fatal("failed to create request: ", err)
return
}
// set extra headers
h := req.Header
h.Set(gateway.XSerializeType, "3")
h.Set(gateway.XServicePath, "Arith")
h.Set(gateway.XServiceMethod, "Mul")
// send to gateway
res, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatal("failed to call: ", err)
}
defer res.Body.Close()
// handle http response
replyData, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Fatal("failed to read response: ", err)
}
// parse reply
reply := &Reply{}
err = cc.Decode(replyData, reply)
if err != nil {
log.Fatal("failed to decode reply: ", err)
}
log.Printf("%d * %d = %d", args.A, args.B, reply.C)
}
FAQs
Unknown package
Did you know?
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.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.