shogowada / json-rpc-2.0

Let your client and server talk over function calls under JSON-RPC 2.0 spec. Strongly typed. No external dependencies.

Home Page:https://www.npmjs.com/package/json-rpc-2.0

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

feat: Extensions

saul-jb opened this issue · comments

commented

Following on from #47, do you think it be a good idea to add extensions to the classes that would provided a way to handle third party extensions that could be added as a configuration option?

const server = new JSONRPCServer({
  extensions: {
    iterable: iterableExt(),
    cancelable: cancelableExt()
  }
});

// Use an extension.
server.ext.iterable.add(/* ... */);

This way anyone can make use of official and private extensions that follow the JSON-RPC 2.0 Extension specification.

It supports middleware. Does that suffice, or are you thinking of something else?

commented

It supports middleware. Does that suffice, or are you thinking of something else?

At first I didn't think it would be flexible enough but it seems functionality can be extended (albeit a little awkwardly) by leveraging client/server params.

Thanks for your help.

commented

At first I didn't think it would be flexible enough but it seems functionality can be extended (albeit a little awkwardly) by leveraging client/server params.

I just realized that there is no middleware on the client side - is there an existing system to modify requests/responses on the client side?

I know modifying the client's request/response could be done in many other ways but the point is to make it a generic module that could be added to modify behavior without needing to change any other configuration or setup or have to extend the class from this directly. Middleware for the JSONRPCClient should be enough to achieve this.

is there an existing system to modify requests/responses on the client side?

You can modify request on the function you give to the JSONRPCClient's constructor, and modify the response before giving it to receive method.

I know modifying the client's request/response could be done in many other ways but the point is to make it a generic module that could be added to modify behavior without needing to change any other configuration or setup or have to extend the class from this directly.

OK.

Middleware for the JSONRPCClient should be enough to achieve this.

What kind of API are you thinking of for the client side middleware?

commented

What kind of API are you thinking of for the client side middleware?

I think the same as the server side should do, adapted for the client:

async (next, request, clientParams) => {}

Then the request can be altered before calling next and the response can be altered by manipulating the return value of it.

Yeah I see some use cases for it. I might take a look in coming weeks. Thanks for the idea!