AngularJS and Spark Post request problem (The requested route has not been mapped in Spark)

1,762 views
Skip to first unread message

Mirco

unread,
Mar 19, 2015, 3:37:26 AM3/19/15
to spar...@googlegroups.com
Hi there,

I'm a bit stuck and hopefully somebody can help. I'm trying to implement a simple CRUD application with Spark and AngularJS.

On the server side I've several endpoints set up like this:

post(API_CONTEXT + "/users,", "application/json", (Request request, Response response) -> {
   
userService.createNewUser(request.body());
    response
.status(201);
   
return response;
}, new JsonTransformer());

get(API_CONTEXT + "/users/:id", "application/json", (Request request, Response response) -> {
   
return userService.findById(request.params(":id"));
}, new JsonTransformer());

get(API_CONTEXT + "/users", "application/json", (Request request, Response response)
       
-> userService.findAll(), new JsonTransformer());

put(API_CONTEXT + "/users/:id", "application/json", (Request request, Response response)
       
-> userService.update(request.params(":id"), request.body()), new JsonTransformer());

Doing a get request from Angular works fine:
resourceProvider.User.query(function (data) {
  $scope
.users = data;
});

But a post request as follows, always fails:

resourceProvider.User.save($scope.user, function(data) {
 
console.log("user saved: " + angular.fromJson(data));
});

I would be grateful for any hints / help.

Christian MICHON

unread,
Mar 19, 2015, 4:37:38 AM3/19/15
to spar...@googlegroups.com
I would suggest to use postman extension on chrome to double check your API regardless of the client (angular).

Can you share the source code of a standalone app showing the issue? Both server and client: I might be able to help out.

Mirco

unread,
Mar 19, 2015, 6:47:25 AM3/19/15
to spar...@googlegroups.com
Hi Christian,

that would be awesome.

I created a sample Spark application. See. https://github.com/m1rc0/Testing
It's stupid but the problem persists. I tried Postman and have the same results.

Greenting

Mirco

unread,
Mar 19, 2015, 8:13:36 AM3/19/15
to spar...@googlegroups.com
I'm somewhat embarrassed right now. But the "error" was simply a copy and paste failure on my side. I forgot an "," in my routes.

Nevertheless thank you very very much

Christian MICHON

unread,
Mar 19, 2015, 10:20:32 AM3/19/15
to spar...@googlegroups.com
Not an issue. "Shift" happens sometimes too.

I did not get to see your reply in time and you already removed the github repo.

Yet please note that in your small snippets in the original post, I can at least say it's not enough to write 'application/json' and use JsonTransformer to ensure true json output.

You need to have response.type("application/json") inside your routes.
Reply all
Reply to author
Forward
0 new messages