Permalink
Browse files

Refactor Library using http interceptors

  • Loading branch information...
Jonatan Männchen authored and maennchen committed Mar 4, 2016
1 parent 79bb3f4 commit e6f39b8aeda50c4358d739f61cd47abd75182cba
Showing with 3,983 additions and 1,792 deletions.
  1. +7 −0 .editorconfig
  2. +11 −4 .jshintrc
  3. +73 −0 Gulpfile.js
  4. +49 −34 README.md
  5. +1,209 −381 angular-hal.js
  6. +20 −0 angular-hal.min.js
  7. +68 −0 demo/app.js
  8. +41 −0 demo/index.html
  9. +140 −0 demo/mocks.js
  10. +0 −14 demo/server.js
  11. +0 −76 demo/src/app.js
  12. +0 −50 demo/src/index.html
  13. +0 −123 demo/src/mocks.js
  14. +0 −25 demo/src/style.css
  15. +25 −0 demo/style.css
  16. +6 −5 karma.conf.js
  17. +28 −4 package.json
  18. +16 −0 src/angular-hal.module.js
  19. +13 −0 src/client/client.module.js
  20. +96 −0 src/client/hal-client.service.js
  21. +96 −0 src/client/link-header.factory.js
  22. +11 −0 src/configuration/configuration.module.js
  23. +121 −0 src/configuration/hal-configuration.provider.js
  24. +23 −0 src/http-interception/http-interception.config.js
  25. +14 −0 src/http-interception/http-interception.module.js
  26. +71 −0 src/http-interception/resource-http-interceptor.factory.js
  27. +32 −0 src/http-interception/response-transformer.service.js
  28. +208 −0 src/resource/hal-resource-client.factory.js
  29. +267 −0 src/resource/resource.factory.js
  30. +14 −0 src/resource/resource.module.js
  31. +11 −0 src/url-generator/url-generator.module.js
  32. +58 −0 src/url-generator/url-generator.service.js
  33. +35 −0 src/utility/define-read-only.factory.js
  34. +35 −0 src/utility/extend-read-only.factory.js
  35. +47 −0 src/utility/normalize-link.factory.js
  36. +44 −0 src/utility/resolve-url.factory.js
  37. +11 −0 src/utility/utility.module.js
  38. +0 −87 test/attributeNames.js
  39. +0 −733 test/halbuilder-test-resources.js
  40. +88 −0 test/integration/attribute-names.spec.js
  41. +725 −0 test/integration/halbuilder-test-resources.spec.js
  42. +201 −0 test/integration/simple.spec.js
  43. +69 −0 test/integration/transform-url.spec.js
  44. +0 −256 test/simple.js
View
@@ -0,0 +1,7 @@
root = true
[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
View
@@ -1,6 +1,13 @@
{
"undef": true,
"sub": true,
"expr": true,
"jasmine": true
"undef": true,
"sub": true,
"expr": true,
"jasmine": true,
"laxcomma": true,
"node": true,
"globals": {
"angular": false,
"module": false,
"inject": false
}
}
View
@@ -0,0 +1,73 @@
var gulp = require('gulp')
, uglify = require('gulp-uglify')
, concat = require('gulp-concat')
, watch = require('gulp-watch')
, jshint = require('gulp-jshint')
, gulpUtil = require('gulp-util')
, angularFilesort = require('gulp-angular-filesort')
, karma = require('karma');
gulp.task('default', [
'compress',
]);
gulp.task('watch', function() {
gulp.start('compress');
watch(__dirname + '/src/**/*.js', function() {
gulp.start('compress');
gulp.start('jshint');
});
watch(__dirname + '/test/**/*.js', function() {
gulp.start('compress');
gulp.start('jshint');
});
});
gulp.task('test', [
'karma',
'jshint',
]);
gulp.task('compress', [
'compress:minified',
'compress:unminified',
]);
gulp.task('compress:unminified', function() {
return gulp.src(__dirname + '/src/**/*.js')
.pipe(angularFilesort())
.pipe(concat('angular-hal.js'))
.pipe(gulp.dest(__dirname));
});
gulp.task('compress:minified', function() {
return gulp.src(__dirname + '/src/**/*.js')
.pipe(angularFilesort())
.pipe(uglify())
.on('error', gulpUtil.log)
.pipe(concat('angular-hal.min.js'))
.pipe(gulp.dest(__dirname));
});
gulp.task('jshint', function() {
return gulp.src([__dirname + '/src/**/*.js', __dirname + '/test/**/*.js'])
.pipe(jshint(__dirname + '/.jshintrc'))
.pipe(jshint.reporter('jshint-stylish'));
});
gulp.task(
'karma',
[
'compress',
],
function (done) {
var server = new karma.Server(
{
configFile: __dirname + '/karma.conf.js',
singleRun: true
},
done
);
server.start();
}
);
View
@@ -2,59 +2,74 @@
[![Build Status](https://travis-ci.org/LuvDaSun/angular-hal.svg?branch=master)](https://travis-ci.org/LuvDaSun/angular-hal)
## Upgrade to Version 2.0
## Help wanted!
### Methods
If you feel like helping out, plese contact me!
| **old** | **new** |
|----------------------|-------------------------------|
| halClient.$* | $http() |
| halClient.LinkHeader | LinkHeader |
| resource.$[method] | resource.$request().$[method] |
## Get It!
## use it in your project!
### NPM
Easy installation using bower
```bash
npm install angular-hal --save
```
bower install angular-hal
### Bower
```bash
bower install angular-hal
```
then, reference the js files in your html page
## Installation
<script src="bower_components/rfc6570/rfc6570.js"></script>
<script src="bower_components/angular-hal/angular-hal.js"></script>
Reference the js files in your html page
```html
<script src="bower_components/rfc6570/rfc6570.js"></script>
<script src="bower_components/angular-hal/angular-hal(.min).js"></script>
```
You may use it like this:
angular
.module('app', ['angular-hal'])
.run([
'$rootScope'
, '$window'
, 'halClient'
, function(
$rootScope
, $window
, halClient
) {
var token = $window.sessionStorage.getItem('token');
$rootScope.apiRoot = halClient.$get('https://api.example.com/', {
authorization: token && 'Bearer ' + token + ''
});
$rootScope.$watch('apiRoot', function(apiRoot){
$rootScope.authenticatedUser = apiRoot.$get('http://example.com/authenticated-user');
});
}
])//run
```js
angular
.module('app', ['angular-hal'])
.run(function($rootScope) {
$rootScope.apiRoot = $http({url: 'https://api.example.com/'});
$rootScope.$watch('apiRoot', function(apiRoot){
$rootScope.authenticatedUser = apiRoot.$request().$get('http://example.com/authenticated-user');
});
}]);
```
stay tuned for more!
## Configuration
Use the provider `$halConfigurationProvider` to configure the module.
### Options
- `setLinksAttribute` - Set links attribute name. (default: `_links`)
- `setEmbeddedAttribute` - Set embedded attribute name. (default: `_embedded`)
- `setIgnoreAttributePrefixes` - Set prefix for meta (hidden) properties. (default: `[ '_', '$' ]`)
- `addIgnoreAttributePrefix` - Add a prefix.
- `setSelfLink` - Set name of self link. (default: `self`)
- `setForceJSONResource` - Force transformation of JSON response into HAL resource. (default: `false`, **!this may break other modules!**)
- `setUrlTransformer` - Set a function to change urls. (deprecated)
## check this out!
- [A blog post by Yuan Ji about Angular-HAL](https://www.jiwhiz.com/post/2014/4/Consume_RESTful_API_With_Angular_HAL)
- [Role-based SPAs with AngularJS and Spring HATEOAS](https://paulcwarren.wordpress.com/2015/04/03/role-based-spas-with-angularjs-and-spring-hateoas/)
- [Hypermedia REST API client for AngularJS applications](https://github.com/jcassee/angular-hypermedia)
- [A blog post by Yuan Ji about Angular-HAL](https://www.jiwhiz.com/post/2014/4/Consume_RESTful_API_With_Angular_HAL)
- [Role-based SPAs with AngularJS and Spring HATEOAS](https://paulcwarren.wordpress.com/2015/04/03/role-based-spas-with-angularjs-and-spring-hateoas/)
- [Hypermedia REST API client for AngularJS applications](https://github.com/jcassee/angular-hypermedia)
## compatibility
Oops, something went wrong.

0 comments on commit e6f39b8

Please sign in to comment.