URL parameters in $ httpBackend (angularJS)

Is it possible to get the URL parameter in $ httpBackend in angularJS? I would like to do something like:

$httpBackend.whenGET('/api/v1/users/{userId}').respond(function (method, url, data) { // somehow read {userId} and act differently depending on what the value is return [200]; }); 

Having this functionality will really simplify the creation of a fairly functional mock API (it is easier to develop an external application without having to run the entire backend).

+6
source share
1 answer

You can pass a regular expression instead of a string as a URL. In the callback function, retrieve the userId from the URL and respond to what you want.

+4
source

Source: https://habr.com/ru/post/950878/


All Articles