How do I link php slim with Ionic


#1

this is the code in ionic to link to my slim api:

postData(credentials, type){

return new Promise((resolve, reject) =>{
  let headers = new Headers();
  this.http.post("http://slimapp:8080/api/signup", JSON.stringify(credentials), {headers: headers}).
  subscribe(res =>{
    resolve(res.json());
  }, (err) =>{
    reject(err);
  });
});

}

credentials is my data and type is"signup"

and this is the slim php code tp match the route
$app->post(’/api/signup’, function(Request $request, Response $response){
// my function is here
});

when i connect postman with php slim, everything works well, but when i connect it with ionic, this error comes up:
[404]: /api/signup - No such file or directory

how to fix this?


#2

The most likely reason is you are not hitting the correct route with your postman request. Are you certain the URL is correct? Are you sending it as a POST request? If you look at the server log, does it show it as a POST request at the correct URL?