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

GET query parameters #32

Open
niklasva82 opened this issue Dec 1, 2020 · 2 comments · May be fixed by #33
Open

GET query parameters #32

niklasva82 opened this issue Dec 1, 2020 · 2 comments · May be fixed by #33

Comments

@niklasva82
Copy link
Member

niklasva82 commented Dec 1, 2020

Implement a standard way of passing GET query parameters to a resource.

There are a few options here.

Currently, the main use for this the recursive flag. This could be added as an option to the get() function, but the absence of proper named parameters in JS makes this cumbersome, and maintaining compatibility would require calls like get(null, null, null, true), or if we want to make it more generic, get(null, null, null, { recursive: 2 })

Another option is for the option of adding a last object parameter to any request, as in z.resource('orgs',4,'sub_orgs',{ recursive: true })

A third option is to add a function similar to the meta function, as in z.resource('orgs',4,'sub_orgs').query({ recursive: 4 })

What do you think @richardolsson? Do you have anything specific in mind?

@richardolsson
Copy link
Member

richardolsson commented Dec 1, 2020

Great suggestions! I like both of the solutions that are based on objects ({ recursive: x }).

I think I like the look of z.resource('orgs', 4, 'sub_orgs', { recursive: true }) best, but it does present a new risk for programmer mistakes. Consider the following code:

const retrievePerson = (person) => {
  // Expects person to be an ID
  return z.resource('orgs', 1, 'people', person);
};

// Passing an object, WITH and ID
retrievePerson({
  id: 1857,
  first_name: 'Clara',
  last_name: 'Zetkin',
});

The code contains a mistake. Instead of passing an ID, it passes an object which contains an ID. There would be no way for the SDK to detect that this was a mistake, because the object will be interpreted as a query object, and the request will be made to /orgs/1/people?id=1857&first_name=Clara&last_name=Zetkin instead of /orgs/1/people/1857 as was probably intended.

Do we consider this a problem? What do you think @niklasva82?

@niklasva82
Copy link
Member Author

I also think that syntax is the most attractive. I understand the issue but I also don't think it will be a major one. If a programmer does this by mistake, then it simply won't work. I will implement something like this proposal.

@niklasva82 niklasva82 linked a pull request Dec 1, 2020 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants