-
Notifications
You must be signed in to change notification settings - Fork 117
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
How to read multiple queryParams #16
Comments
As suggested on Stackoverflow (http://stackoverflow.com/questions/28859371/meteor-restivus-how-to-read-multiple-queryparams?noredirect=1#comment46083182_28859371) here is the test result. |
If you look at the last two tests there, you'll see that they are designed to test what you were asking about (an endpoint being able to access multiple query params. If you look at the tests for those you'll see that I'm testing exactly what you're doing above:
As you can see in both of those tests, I'm testing for the values of multiple query params to verify having access to them. I do this by making an HTTP request with all the query params in the url and then testing for those values in my |
I believe you :) |
I just tested your code and it worked fine. The only thing I had to do is what I discussed in your other issue (#17), as far as making sure something was returned from the endpoint. Here is the code, but again, nothing is different except making sure something is returned. For this example, I return whatever values you pass as query params. If you would like to test it out, just make a if (Meteor.isServer) {
Meteor.startup(function () {
// RESTIVUS
// Global configuration
Restivus.configure({
useAuth: false,
prettyJson: true
});
// Given the url: "/posts?key=1234&value1=10"
Restivus.addRoute('posts', {
get: function () {
var key = this.queryParams.key;
var value1 = this.queryParams.value1;
console.log("key: " + key); // result: 1234
console.log("value1: " + value1); // result: 10
return {
key: key,
value1: value1
}
}
});
});
} |
Thanks for your support! But it's still not working. I think I am going crazy. When I paste your code into a new project I get "undefined" again. |
I was this close to thinking I was losing my mind as well, but I figured it out! You're using curl to test, right? Well apparently (and don't feel bad for not knowing this, because neither did I), the Let me know if this fixes your problem. Hopefully, this prevents you from losing any further sanity! |
F***... it works! |
Haha. Awesome! Glad we finally got to the bottom of this. Thanks for closing. |
In a custom route I would like to have multiple values as queryParams like this (e.g. value1 and value2):
...domain/api/update?key=1234&value1=10
How do I get them in endpoint function?
When I try this I get undefined:
This is my code in a new standard Meteor project with only Restivus package added.
Meteor version 1.0.3.2
The text was updated successfully, but these errors were encountered: