Angular sends the body of the message (data) as application/json , while forms usually send as application/x-www-form-urlencoded . Pyramid parses the body and allows you to access it in request.POST when it is encoded as normal form.
It is not possible to represent all data encoded in the Angular (json) way as a key / value pair, as provided by the pyramid API.
[ 1, 2, 3, 4 ]
Pyramid side decision
It can be allowed to view or globally
In view
This is a pyramidal way and the most flexible way to handle it.
@view_config(renderer='json') def myview(request): data = request.json_body
Worldwide
The pyramid will most likely be installed on the assumption that the body encoded as application/json is an object and its properties will be placed in the request. POST
Angular side solution
As for the side of the pyramid, it can be solved on request and around the world.
Per request
You need to send data, as forms are usually sent:
$http({ method: 'POST', url: url, headers: {'Content-Type': 'application/x-www-form-urlencoded'}, transformRequest: function(obj) { var str = []; for(var p in obj) { if (obj.hasOwnProperty(p)) { str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p])); } } return str.join("&"); }, data: xsrf }).success(function () {});
Worldwide
To send messages by default form, configure $ httpProvider for this.
angular.module('httpPostAsForm', []) .config(['$httpProvider', function ($httpProvider) { $httpProvider.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded"; $httpProvider.defaults.transformRequest.unshift(function (obj) { var str = []; for(var p in obj) { if (obj.hasOwnProperty(p)) { str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p])); } } return str.join("&"); }); }]);
Then include this module in your application:
angular.module("app", ["httpPostAsForm"]);