I'm currently using Symfony with FosRestBundle to create an Api.
In symfony I would like to catch a request from the client to give back some informations. (So a get methode).
This is my code who permit the communication between the api and the client.
Api Side :
public function getPropertiesAction(Request $request){
$properties = $this->getDoctrine()->getManager()->getRepository('ApiBundle:Achats')->findAll();
if(null == $properties){
throw $this->createNotFoundException();
}
$data = findPropertiesInside($properties, $request);
return $data;
}
Client side :
angular.module('googleMapApp')
.service('PropertiesData', function ($http) {
this.fetch = function(url, polygone, callback, errorCallback) {
$http.post(url,{data: polygone}).then(callback,errorCallback);
};
});
So when i do that the api return error 405 (Method Not Allowed)
Is there a way to send post json informations from the client to the api and the api return the good properties?
You cannot pass a request body when using HTTP GET. You should pass the data in the url, either using the path or the query string.
Change your client side to $http.get(urlWithData).then...