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.

Suraj Singh
  • 4,041
  • 1
  • 21
  • 36
visst
  • 1,351
  • 2
  • 11
  • 10
  • 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` – Pankaj Parkar Apr 16 '15 at 11:46
  • Are you using spring rest controller on the other side? – rebeliagamer Apr 16 '15 at 12:45

1 Answers1

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

Community
  • 1
  • 1
rebeliagamer
  • 1,257
  • 17
  • 33