Suppose I have the following test code in AngularJS:
var someURL; var dummyJSON; $httpBackend.whenGET(someURL).respond(dummyJSON);
Is there a way to make this answer for a set of URLs, not just one? For example, I would like it to respond with the same JSON dummy for ANY URL that starts with / api /, but not with those starting with / app /. How is the wildcard URL ("/ app / *")?
thanks for the help
I got lucky with type expressions whenGET(/^\/api\//)- that means it starts with /api/. In the regex, it ^will match the beginning of the line, and \/will match the literal /in the url.
whenGET(/^\/api\//)
/api/
^
\/
/
, whenGET(/\/api\//), URL-, URL-.
whenGET(/\/api\//)
, . - :
$httpBackend.when("GET", function(url) {return url.indexOf("/api/") === 0;}