Search code examples
javaurlhttp-postspring-web

Finding the fully qualified URL of a function annotated with @RequestMapping


I have been given a Java project to work with, which contains a function to which I need to make a POST request, from an Angular frontend.

The function is annotated with: @RequestMapping(value = "/fn", ...) and will be tested on a local server (Wildfly 8.x).

Where can I find the values that are need to determine the URL that I need to specify in the HTTP.post() method (from HttpClientModule), from the frontend, to access this function?


Solution

  • The "value" parameter to the @RequestMapping annotation is the relative path in url that will result in invoking the annotated method. BTW, "value" is an alias for "path", so you may see "value=", "path=", or just the raw string without a property name - all three are equivalent.

    Note that the Controller object (the object that contains the method) can also have a @RequestMapping, and in that case, the method's path is appended to the controller's path.

    So the path would be the application's base url, e.g. "http://myapp:8080" plus the controller path, e.g. "/widgets", plus the method path, e.g. "/list", resulting in a url of, e.g. "http://myapp:8080/widgets/list".