Tuesday, May 21, 2024
 Popular · Latest · Hot · Upcoming
173
rated 0 times [  176] [ 3]  / answers: 1 / hits: 15794  / 11 Years ago, thu, february 13, 2014, 12:00:00

In my RESTful api one of the resources exposes a GET method that accept json as a parameter named 'query'. This parameter is passed directly to the MongoDB query allowing users to query the database directly using mongo syntax.



The problem I'm having is that the request always looks like this:



?&query=%7B%22source%22:%22incident%22%7D 


Where it should look something like this:



?&query={'source': 'incident'} 


This is how I am sending the GET request:



var query = {};
if ($scope.sourceFilter) { query.source = $scope.sourceFilter; }
var query = JSON.stringify(query);
$http.get('/api/feedbackEntries', {params: {limit: $scope.limit, query: query}}).success(function(data) { .......


I am doing the same thing on other get requests and I don't get this issue.



Am I doing something wrong here ? Is this to do with the way angular parses params ?



Thanks


More From » json

 Answers
19

After some digging I figured this one out. Looking at the request I was making:



$http.get('/api/feedbackEntries',


I saw that the url does not end with a trailing slash. This was the only difference I could see compared with other requests that were working fine. So I added the trailing slash and magically it works. I can't explain why, whether it's something within angular or elsewhere .. but this is how I fixed the problem.



Hope this helps someone in the future.


[#72543] Wednesday, February 12, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
marissatinao

Total Points: 447
Total Questions: 90
Total Answers: 93

Location: Puerto Rico
Member since Sun, Jun 27, 2021
3 Years ago
;