Skip to content
Advertisement

How to add a full URL as an endpoint to a GET request

I’m trying to make a GET request and add a full url a a variable like so

     * @Route("/foobar/{url}", name="foobar", methods={"GET"})

When i however try to call this in postman

http://foo.bar.local/post/https://www.google.de/

I get

   No route found for "GET /foobar/https://www.google.de/"

However if i do anything else, for example

1
www.google.de

I get the correct response

What am I doing wrong ?

Advertisement

Answer

You can add a requirements on your route annotation like:

/**
 * @Route("/url-test/{url}", name="url_test", methods={"GET"}, requirements={"url"=".+"})
 */
public function url_test($url)
{
    dump($url); // https://www.google.de/
}

And to check I use the url : https://127.0.0.1:8000/url-test/https://www.google.de/

Documentation: https://symfony.com/doc/4.1/routing/slash_in_parameter.html

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement