简体   繁体   中英

REST API / DELETE METHOD / Slim Framework v3

I am currently in the process of learning how to buid my own REST API using the Slim Framework v3 for PHP. I found several tutorials and was able to build multiple routes to send GET and POST requests to my MySQL database. Next up for me is a delete request, but it doesn't work.

This is my code:

$app->delete('/usuario/[{correo}]', function ($request, $response, $args) {
  $sth = $this->db->prepare("DELETE FROM usuarios WHERE email=:correo");
  $sth->bindParam("correo", $args['correo']);
  $sth->execute();
  $todos = $sth->fetchAll();
  return $this->response->withJson($todos);
});

I'm testing it in Postman and I always have the same problem: 404 Not found. I can't understand it because I think the url is correct ( http://localhost:8080/usuario/bbb@bbb.es ).

Postman view

Can anyone help me?

I think the problem was in the parameter you sent to the route

You can not send dots as a character in your route URL IF you test
I guess if you test http://localhost:8080/usuario/bbb@bbbdotes It will work fine

You can send the email address in the body not in the url

{"email":"bbb@bbbdotes"}

And then you can deal with it like POST route to fetch the email address

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM