1

I'm trying to send a request to the server with 4 parameters. It seems to work with less than 4, but I cannot get it to work with 4 or more. Here are the snippets:

        historyy: $resource('/history/:user.:item.:count.:cost', {

            user: '@userr',
            item: '@itemm',
            count: '@countt',
            cost: '@costt'
        }

Calling RestService:

   RestServices.historyy.get({userr: "Asd",itemm: $scope.item.id,countt: amount,costt: '0' });

When I execute this, the URL looks like this:

http://localhost:8080/history/...?costt=0&countt=6&itemm=1&userr=Asd

Why is it adding these crazy (...?) ?. When I remove one of the parameter (no matter which one) it works properly.

2
  • Adding ? to start of the query string is normal thing, what the . next after the parameter does $resource('/history/:user.:item.:count.:cost', {, I think it should be $resource('/history/:user:item:count:cost Commented Apr 16, 2015 at 11:46
  • Are you using spring rest controller on the other side? Commented Apr 16, 2015 at 12:45

1 Answer 1

1

You can use query (see: doc)

Resource

$resource('/history/');

Call

RestServices.historyy.query({user: "Asd", item: $scope.item.id, ...}, function(results) {
  //on success
});

Result

/history?user=Asd&item=ExampleItem...

Spring REST Controller

@RestController
@RequestMapping(value = "/history", produces = MediaType.APPLICATION_JSON_VALUE)
public class SomeRestController {

    @ResponseBody
    @RequestMapping(method = RequestMethod.GET)
    @JsonView(View.List.class)
    public List<SomeThing> getSomething(
        @RequestParam(value = "user", required = true) String user,
        @RequestParam(value = "item", required = true) String item, ...) {...}

You can find more information here: Using $resource.query with params object

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.