I have this curl line:
curl -X POST -H "content-type: application/json" -H "AUTH_TOKEN: vLC4grMuKbtbamJL3L6x" localhost:8080/v1/segments?appkey=c2439fb30a1cad03e9e02bd733ef2ad5 -d '{"segment" : {"segment_name" : "ャロットケーキが好き", "segment_type":"static"}}'
Now that curl directly hits the API. I'd like to be able to do a $http POST after the save and redirection back to route 'return region.$save((function() {':
'use strict';
angular.module('otherLevelsApp').controller('GeoRegionCreateCtrl', [
'$scope', '$location', 'GeoRegion', 'Hours', '$http', function($scope, $location, GeoRegion, Hours, $http) {
console.log('new region controller');
$scope.app_id = (/apps\/(\d+)/.exec($location.absUrl())[1]);
$scope.newGeoRegion = true;
$scope.geoRegionId = '';
$scope.hours = Hours;
console.log('$scope.hours', $scope.hours);
$scope.geoRegion = {
app_id: $scope.app_id,
geoRegion_id: '',
latitude: 37.7879938,
longitude: -122.40743739,
name: '',
address: '',
radius: 500,
customer_id: $scope.customer_id
};
_.delay((function() {
return $scope.setupGoogleMap();
}), 500);
window.test_scope = $scope;
return $scope.updateOrAddGeoRegion = function() {
var region;
$scope.loading = true;
console.log('creating new region with ', $scope);
region = new GeoRegion($scope.geoRegion);
console.log('region', region);
return region.$save((function() {
return $location.path("/");
}), function(response) {
if (response.data.errors) {
$scope.errors = response.data.errors;
} else {
$scope.errors = {
"Error": ["There was a problem connecting with the server. Please try again later."]
};
}
return $scope.loading = false;
});
};
} ]);
Do you know how I can format it correctly in a $http POST? In particular, do I need to refactor the success and error into the $http code? Ie. Success redirects to return $location.path("/") or...?
I imagine it's something along these lines, but unsure how to finish it off:
$http({
method: 'POST',
url: '',
data: '',
headers: {'Content-Type': 'application/JSON'}
});
Though I am reading Angular doc here: https://docs.angularjs.org/api/ng/service/$http#post I am still a bit confused as to how to directly hit this curl with a $http post?
Appreciate any help!