Permalink
Browse files

feat(common): new HttpClient API

HttpClient is an evolution of the existing Angular HTTP API, which exists
alongside of it in a separate package, @angular/common/http. This structure
ensures that existing codebases can slowly migrate to the new API.

The new API improves significantly on the ergonomics and features of the legacy
API. A partial list of new features includes:

* Typed, synchronous response body access, including support for JSON body types
* JSON is an assumed default and no longer needs to be explicitly parsed
* Interceptors allow middleware logic to be inserted into the pipeline
* Immutable request/response objects
* Progress events for both request upload and response download
* Post-request verification & flush based testing framework
  • Loading branch information...
alxhub authored and Jason Aden committed Mar 23, 2017
1 parent 2a7ebbe commit 37797e2b4e1ddc6560ae6c8364ea678ffbaa3de1
Showing with 5,599 additions and 40 deletions.
  1. +1 −1 npm-shrinkwrap.clean.json
  2. +3 −3 npm-shrinkwrap.json
  3. +1 −1 package.json
  4. +1 −0 packages/common/BUILD
  5. +14 −0 packages/common/http/index.ts
  6. +7 −0 packages/common/http/package.json
  7. +18 −0 packages/common/http/public_api.ts
  8. +21 −0 packages/common/http/rollup.config.js
  9. +25 −0 packages/common/http/src/backend.ts
  10. +891 −0 packages/common/http/src/client.ts
  11. +214 −0 packages/common/http/src/headers.ts
  12. +66 −0 packages/common/http/src/interceptor.ts
  13. +224 −0 packages/common/http/src/jsonp.ts
  14. +93 −0 packages/common/http/src/module.ts
  15. +325 −0 packages/common/http/src/request.ts
  16. +329 −0 packages/common/http/src/response.ts
  17. +214 −0 packages/common/http/src/url_encoded_body.ts
  18. +327 −0 packages/common/http/src/xhr.ts
  19. +114 −0 packages/common/http/test/client_spec.ts
  20. +144 −0 packages/common/http/test/headers_spec.ts
  21. +44 −0 packages/common/http/test/jsonp_mock.ts
  22. +75 −0 packages/common/http/test/jsonp_spec.ts
  23. +88 −0 packages/common/http/test/module_spec.ts
  24. +136 −0 packages/common/http/test/request_spec.ts
  25. +78 −0 packages/common/http/test/response_spec.ts
  26. +76 −0 packages/common/http/test/url_encoded_body_spec.ts
  27. +119 −0 packages/common/http/test/xhr_mock.ts
  28. +306 −0 packages/common/http/test/xhr_spec.ts
  29. +9 −0 packages/common/http/testing/index.ts
  30. +7 −0 packages/common/http/testing/package.json
  31. +11 −0 packages/common/http/testing/public_api.ts
  32. +29 −0 packages/common/http/testing/rollup.config.js
  33. +49 −0 packages/common/http/testing/src/api.ts
  34. +124 −0 packages/common/http/testing/src/backend.ts
  35. +34 −0 packages/common/http/testing/src/module.ts
  36. +200 −0 packages/common/http/testing/src/request.ts
  37. +32 −0 packages/common/http/testing/tsconfig-build.json
  38. +30 −0 packages/common/http/tsconfig-build.json
  39. +2 −2 packages/platform-browser/src/dom/dom_tokens.ts
  40. +70 −31 packages/platform-server/src/http.ts
  41. +2 −1 packages/platform-server/src/server.ts
  42. +1 −0 packages/platform-server/tsconfig-build.json
  43. +2 −0 test-main.js
  44. +1 −0 tools/gulp-tasks/public-api.js
  45. +3 −0 tools/public_api_guard/common/common.d.ts
  46. +991 −0 tools/public_api_guard/common/http.d.ts
  47. +47 −0 tools/public_api_guard/common/http/testing.d.ts
  48. +1 −1 tools/public_api_guard/platform-browser/platform-browser.d.ts
@@ -4807,7 +4807,7 @@
"version": "1.0.1"
},
"ts-api-guardian": {
"version": "0.2.1",
"version": "0.2.2",
"dependencies": {
"diff": {
"version": "2.2.3"
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -92,7 +92,7 @@
"source-map": "^0.5.6",
"source-map-support": "^0.4.2",
"systemjs": "0.18.10",
"ts-api-guardian": "^0.2.1",
"ts-api-guardian": "^0.2.2",
"tsickle": "^0.21.1",
"tslint": "^4.1.1",
"tslint-eslint-rules": "^3.1.0",
View
@@ -4,6 +4,7 @@ load("@io_bazel_rules_typescript//:defs.bzl", "ts_library")
ts_library(
name = "common",
srcs = glob(["**/*.ts"], exclude=[
"http/**",
"test/**",
"testing/**",
]),
@@ -0,0 +1,14 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
// This file is not used to build this module. It is only used during editing
// by the TypeScript language service and during build for verification. `ngc`
// replaces this file with production index.ts when it rewrites private symbol
// names.
export * from './public_api';
@@ -0,0 +1,7 @@
{
"name": "@angular/common/http",
"typings": "../http.d.ts",
"main": "../bundles/common-http.umd.js",
"module": "../@angular/common/http.es5.js",
"es2015": "../@angular/common/http.js"
}
@@ -0,0 +1,18 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
export {HttpBackend, HttpHandler} from './src/backend';
export {HttpClient} from './src/client';
export {HttpHeaders} from './src/headers';
export {HTTP_INTERCEPTORS, HttpInterceptor} from './src/interceptor';
export {JsonpClientBackend, JsonpInterceptor} from './src/jsonp';
export {HttpClientJsonpModule, HttpClientModule, interceptingHandler as ɵinterceptingHandler} from './src/module';
export {HttpRequest} from './src/request';
export {HttpDownloadProgressEvent, HttpErrorResponse, HttpEvent, HttpEventType, HttpHeaderResponse, HttpProgressEvent, HttpResponse, HttpResponseBase, HttpSentEvent, HttpUserEvent} from './src/response';
export {HttpStandardUrlParameterCodec, HttpUrlEncodedBody, HttpUrlParameterCodec} from './src/url_encoded_body';
export {HttpXhrBackend, XhrFactory} from './src/xhr';
@@ -0,0 +1,21 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
export default {
entry: '../../../dist/packages-dist/common/@angular/common/http.es5.js',
dest: '../../../dist/packages-dist/common/bundles/common-http.umd.js',
format: 'umd',
exports: 'named',
moduleName: 'ng.commmon.http',
globals: {
'@angular/core': 'ng.core',
'@angular/platform-browser': 'ng.platformBrowser',
'rxjs/Observable': 'Rx',
'rxjs/Subject': 'Rx'
}
};
@@ -0,0 +1,25 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {Observable} from 'rxjs/Observable';
import {HttpRequest} from './request';
import {HttpEvent} from './response';
/**
* @experimental
*/
export abstract class HttpHandler {
abstract handle(req: HttpRequest<any>): Observable<HttpEvent<any>>;
}
/**
* @experimental
*/
export abstract class HttpBackend implements HttpHandler {
abstract handle(req: HttpRequest<any>): Observable<HttpEvent<any>>;
}
Oops, something went wrong.

2 comments on commit 37797e2

@mmc41

This comment has been minimized.

Show comment
Hide comment
@mmc41

mmc41 Jul 15, 2017

Interesting feature but not so useful without support in the in-memory-api (angular-in-memory-web-api) which both my tests and serverless development approach needs.

mmc41 replied Jul 15, 2017

Interesting feature but not so useful without support in the in-memory-api (angular-in-memory-web-api) which both my tests and serverless development approach needs.

@lizhuangs

This comment has been minimized.

Show comment
Hide comment
@lizhuangs

lizhuangs Sep 21, 2017

plz support angular-in-memory-web-api.Tks~

lizhuangs replied Sep 21, 2017

plz support angular-in-memory-web-api.Tks~

Please sign in to comment.