Why does not my custom API endpoint work?

I've tried to include this code in my php plugin files as well as in functions.php.
(In the end, I'd like it to be in the php file of the plug-in but I'm not sure if that's possible, that would probably be the subject of a another question.)

It's a very basic method at the moment, I'm just trying to get an answer with content.

In both cases, I receive a 404 response.

add_action (& # 39; rest_api_init & # 39 ;, function () {
register_rest_route (plugin_dir_url (__ DIR __). my-project / api / v1 / form, # / action-#, array (
& # 39; methods & # 39; => & # 39; GET, POST & # 39;
& # 39; callback & # 39; => & # 39; api_method & # 39;
));
});

function api_method ($ data) {
var_dump ($ data);
return API method end. & # 39 ;;
}

And I tried to access the URLs (in brower or with AJAX)

  • http: //my-domain.local/wp-content/plugins/my-project/api/v1/form
  • http: //my-domain.local/wp-content/plugins/my-project/api/v1/form/
  • http: //my-domain.local/wp-content/plugins/my-project/api/v1/form/get
  • http: //my-domain.local/wp-content/plugins/my-project/api/v1/form/get/

I guess I'm missing something.