1

How can I make REST POST call in AngularJS, when there are multiple arguments? Here's simple example:

Java REST service (server side):

@RequestMapping(value = "/create", method = RequestMethod.POST)
public void create(@RequestBody Person person, @RequestBody int maxPeople) {
    service.create(person, maxPeople);
}

AngularJS REST factory (client side):

app.factory('PersonService', function ($resource) {
    return $resource('/api/person/create', {}, {
        save: { method: 'POST'}
    });
});

Angular controller:

app.controller('PersonController', function (PersonService) {
    PersonService.save({"name": "John"}, 2);
});

The crucial fragment is: PersonService.save({"name": "John"}, 2); This one doesn't work, I can't figure out how to pass there multiple parameters. What is the correct approach?

MrCrow
  • 23
  • 4
  • post the code in your `$resource` definition. basically, for `$resource`, there is only one argument, with as many properties in the object. your case would probably be `{name: 'john', id: 2}` or something like that – Daniel Lizik Aug 15 '16 at 17:02

1 Answers1

0

Alright, I just realised that we shouldn't have multiple @RequestBody parameters in a method...

Therefore my problem seems to be solved, it was more server-side issue, we just have to hold all arguments in the one json.

Community
  • 1
  • 1
MrCrow
  • 23
  • 4