Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Extensions #48

Open
saul-jb opened this issue Jun 13, 2023 · 6 comments
Open

feat: Extensions #48

saul-jb opened this issue Jun 13, 2023 · 6 comments

Comments

@saul-jb
Copy link
Contributor

saul-jb commented Jun 13, 2023

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.

@shogowada
Copy link
Owner

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

@saul-jb
Copy link
Contributor Author

saul-jb commented Jun 16, 2023

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.

@saul-jb saul-jb closed this as completed Jun 16, 2023
@saul-jb
Copy link
Contributor Author

saul-jb commented Jun 16, 2023

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.

@saul-jb saul-jb reopened this Jun 16, 2023
@shogowada
Copy link
Owner

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?

@saul-jb
Copy link
Contributor Author

saul-jb commented Jul 2, 2023

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.

@shogowada
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants