0.1.1 • Published 9 years ago

ng-http-rewrite v0.1.1

Weekly downloads
5
License
ISC
Repository
-
Last release
9 years ago

ngHttpRewrite

This is just a simple module that allows users to rewrite outgoing urls in Angular without having to jump through hoops of creating interceptors. The idea behind this is that your entire project can use a simple prefix like /api in all of their urls and have them all rewritten at one location. This prevents code duplication.

Installation

npm i ng-http-rewrite --save

Usage

// This is not a CommonJS module. If you're using Webpack just load it like this.
var angular = require('angular');
require('ng-http-rewrite');

angular.module('yourModule', ['lambdaexpression.httpRewrite'])
  .config(function(httpRewriteProvider) {
    // Note that the first argument is a regular expression.
    // Do *not* include trailing slashes unless you want them to be removed.
    // Everything that matches the regular expression is replaced with the
    // secondary string.
    httpRewriteProvider.rewrite(/^\/api/, '/my/rewritten/location');
  });

There is no run-time API for the url rewriter and it only works on outgoing $http requests. It will not re-write the urls of incoming requests (not would it make any sense to). Check tests for usage if you really need to.

Any issues?

Feel free to open an issue if you have any issues or feature requests. Pull requests are also accepted providing you have tests (we're using jasmine/karma).