restangular icon indicating copy to clipboard operation
restangular copied to clipboard

how to specify URLs through symfony route names with restangular?

Open mappedinn opened this issue 9 years ago • 5 comments

Hi,

I am new to restangular. My goal is just to try an example on symfony + angularjs + restangular.

I managed to make the example working. But, this required me to start a webserver through that command $ php app/console server:run localhost:8080

But, this is not what I am looking for. It's a symfony project and I am expecting to make trials on it with that url in my localhost: http://localhost/symfony-angular-todomvc/web/app_dev.php/TodoMVC

In fact, without running that command $ php app/console server:run localhost:8080, I am getting error telling that

GET XHR http://localhost/todos [HTTP/1.1 404 Not Found 0ms]

I solved that by specifying the setting the base URL in the that line L26 as follows:

RestangularProvider.setBaseUrl('/symfony-angular-todomvc/web/app_dev.php/');

So, my question is: "is it possible to specify the URLs when calling the API through symfony route name?" (I am asking this question to avoid setting a base url and then setting the allurl Restangular.allUrl('todos');)

Hint: Routing.generate('route_name') from FOSJsRoutingBundle could be a solution?

Thank you in advance

mappedinn avatar May 24 '16 02:05 mappedinn

my question is: "is it possible to specify the URLs when calling the API through symfony route name?"

Yes:


// Include http://localhost in the URL
RestangularProvider.setBaseUrl("http://localhost/symfony-angular-todomvc/web/app_dev.php/TodoMVC");

daviesgeek avatar Jun 16 '16 21:06 daviesgeek

And what about Routing.generate('route_name') from FOSJsRoutingBundle?

Is it possible?

mappedinn avatar Jun 16 '16 22:06 mappedinn

I'm not sure what you're talking about since I'm not familiar with the library in question. Can you please elaborate?

daviesgeek avatar Jun 17 '16 00:06 daviesgeek

Hi @mappedinn you can use FOSJsRouting and expose symfony's routes

miguelplazasr avatar Jul 24 '16 04:07 miguelplazasr

Thank you @miguelplazasr for your answer.

Can you please how it would become in this case the code below?

RestangularProvider.setBaseUrl('/symfony-angular-todomvc/web/app_dev.php/');

Thanks again!

mappedinn avatar Jul 24 '16 16:07 mappedinn