6

Is it possible to receive an 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 would really make it easy to create a rather functional mock API (easier to develop the front-end application without having to run the whole backend).

1 Answer 1

4

You can pass a regexp instead of a string as the URL. In the callback function, extract the userId from the URL, and answer what you want.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, Sir. Should anyone need an exemplary RegExp for that purpose, please consider mine: /^/items/\d$/ Hope it helps, too!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.