-
Notifications
You must be signed in to change notification settings - Fork 2
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
Comments
Great suggestions! I like both of the solutions that are based on objects ( I think I like the look of 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? |
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. |
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?
The text was updated successfully, but these errors were encountered: