Skip to content

Commit

Permalink
feat(common): new HttpClient API
Browse files Browse the repository at this point in the history
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 Jul 7, 2017
1 parent 2a7ebbe commit 37797e2
Show file tree
Hide file tree
Showing 48 changed files with 5,599 additions and 40 deletions.
2 changes: 1 addition & 1 deletion npm-shrinkwrap.clean.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions packages/common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ load("@io_bazel_rules_typescript//:defs.bzl", "ts_library")
ts_library(
name = "common",
srcs = glob(["**/*.ts"], exclude=[
"http/**",
"test/**",
"testing/**",
]),
Expand Down
14 changes: 14 additions & 0 deletions packages/common/http/index.ts
Original file line number Diff line number Diff line change
@@ -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';
7 changes: 7 additions & 0 deletions packages/common/http/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
18 changes: 18 additions & 0 deletions packages/common/http/public_api.ts
Original file line number Diff line number Diff line change
@@ -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';
21 changes: 21 additions & 0 deletions packages/common/http/rollup.config.js
Original file line number Diff line number Diff line change
@@ -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'
}
};
25 changes: 25 additions & 0 deletions packages/common/http/src/backend.ts
Original file line number Diff line number Diff line change
@@ -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>>;
}
Loading

0 comments on commit 37797e2

Please sign in to comment.