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

Inconsistent request/response params structure #763

Open
Sourcebite opened this issue Jan 30, 2023 · 0 comments
Open

Inconsistent request/response params structure #763

Sourcebite opened this issue Jan 30, 2023 · 0 comments

Comments

@Sourcebite
Copy link

Is your feature request related to a problem? Please describe.
Server implementation converts params of request to array with order specified in my own open-rpc document.
I found this a little strange and inconsistent with behavior of client implementation (it is doesn't change params structure if i send params as object with fields).
It also does not allow to have same method interface between frontend and backend.
Altogether, why it is bad?:

  1. Different client/server method interface, cannot be used in front/back monorepo
  2. Cannot be used as drop-in replacement lib without breaking backward compatibility of current services
  3. Under the hood params convertation magic

Describe alternatives you've considered
I could move all params under the user or data parent object, but [see 2nd clause]

Describe the solution you'd like
I would prefer global or method-by-method option to choose params structure

  1. Option to choose preferred params structure
  2. Choose params structure from open-rpc document methods[#].paramStructure (breaking current behavior)

Additional context
Example:

interface CreateUserParams {
    name: string;
    age: number;
    // many other fields
}

// Client side:
class UserService {
    client: Client; // open-rpc client

    create(params: CreateUserParams) {
        this.client.request({
            method: "users.create",
            params: params
        });
    }
}


// Server side:
class UserService {
    create(params: CreateUserParams) {
        console.log(params.name, params.age);
    }
}

const userService = new UserService();

const methodMapping = {
    "users.create": userService.create.bind(userService)
};
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

1 participant