Reputation: 354
I have a Feathersjs API which using REST can serve a GET request to a URL like http://server.com/service-name/:fieldName
where fieldName
has a string value. The API assigns the value of fieldName
to params.query
.
While developing a React Native app, I am trying to make the same request using feathers socketio client. The request looks like this:
return this.app.service('service-name/:fieldName').find({
query:{fieldName='value'}
}).then(response => {
console.log('data from server', response.data); // ignore this console format
}).catch(error => {
console.log(error);
});
The request above makes it to the server, but the value of fieldName
is either undefined
or some other unwanted value because the server returns an empty result set. I have also read that the setSlug hook would be an option, but I am not sure how to do it.
Can someone please help me resolve this issue by sending the real value of fieldName
in the request to the server?
[Edit]
After checking the logs on the API server, I found out that a REST API request has the correct params.route
object:
object(9) {
["query"] => object(0) {}
["route"] => object(1) {
["fieldName"] => string(5) "value"
}
...
The params.route
is empty with the socketio request:
object(9) {
["query"] => object(0) {}
["route"] => object(0) {}
["connection"] => object(6) {
["provider"] => string(8) "socketio"
["payload"] => object(1) {
["userId"] => number(3)
}
...
While I'm relieved to know where the problem is, would anyone please tell me how to correctly set params.route
in React Native using a socketio request?
Upvotes: 0
Views: 314
Reputation: 44215
You can use a normal route just like with HTTP which will set params.route
with fieldName
:
return this.app.service('service-name/something').find({}).then(response => {
console.log('data from server', response.data); // ignore this console format
}).catch(error => {
console.log(error);
});
Will set { params: { route: { fieldName: 'something' } } }
Upvotes: 1