Skip to content

Inconsistent request/response params structure #763

Open
@Sourcebite

Description

@Sourcebite

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)
};

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Sourcebite

        Issue actions

          Inconsistent request/response params structure · Issue #763 · open-rpc/server-js