I've read answers to similar questions here but none seem to correct the problem I'm seeing. Given:
var app = angular.module("eg", ["ngResource", "postAPI"]);
var postAPI = angular.module("postAPI", ["ngResource"]);
postAPI.factory("Post", ["$resource",
function postFactory(resource) {
return resource("/post");
}
]);
postAPI.controller("PostIndexCtrl", ["$scope", "Post",
function($scope, Post) {
Post.query(function(data) {
$scope.response = data;
});
}
]);
postAPI.controller("CreateCtrl", ["$scope", "Post",
function($scope, Post) {
Post.save({
title: "Title",
body: "Body",
tags: ["one", "two", "three"],
});
}
]);
Error received (docs): "Error in resource configuration for action save. Expected response to contain an object but got an array".
Which would be fine, except that as far as I can see my backend does return a single object. Tested with curl:
curl -H "Content-Type: application/json" -X POST -d '{"title":"foo","body":"bar","tags":["wombat"]}' http://localhost:8080/post/
Response:
{"title":"foo","body":"bar","tags":["wombat"],"created":"...","modified":"...","id":12345}
(edits for brevity, same format). The PostIndexCtrl works as expected, returning an array of post objects. Any clues as to why CreateCtrl might be seeing an array when curl works fine?