2

I am trying to dynamically add URL parameter to $httpbackend.whenGET

urlAll = "http://localhost:8080/api/Log";
urlById = "http://localhost:8080/api/Log?id=";
  • $httpBackend.whenGET(urlAll).respond(...); - This is Working fine
  • $httpBackend.whenGET(urlById).respond(...); - Not working

I append id dynamically to urlById when I call mock service. Since it is a dynamic value and the url is changing with dynamic id value, url is not matching with urlById (which is passed to httpbackend). Hence, throwing below exception.

Unexpected request: GET /http:\/\/localhost:8080\/api\/Log?id=/1e970422-a1a7-4ea5-9f74-1c84b53d7bc4
No more request expected

Gone through different posts and tried with regex. but ended up with below exception:

Unexpected request: GET /http:\/\/localhost:8080\/api\/Log\?id=.*/14f99a26-7850-4aa6-9953-db73fb1a1cab
Expected GET /http:\/\/localhost:8080\/api\/Log\?id=.*/.*/g

Any idea on how to add dynamical url to $httpbackend?

Most of the posts say the theoretical solutions and some posts given code changes, which didn't work. Any idea on what is wrong above?

Toby Speight
  • 27,591
  • 48
  • 66
  • 103
Vis
  • 21
  • 3

0 Answers0