Skip to content

Commit 9e0dd6a

Browse files
author
mikhail
committed
Added support for Observe param of request options
1 parent 9fde376 commit 9e0dd6a

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
export * from './src/ngx-http-rest.module';
22
import { Response } from '@angular/http';
3-
import { HttpRestUtils, path, body, query, headers, produces } from "ngx-http-rest/src/ngx-http-rest.utils";
3+
import { HttpRestUtils, path, body, query, headers, produces, observe } from "ngx-http-rest/src/ngx-http-rest.utils";
44

55
export let Path = path;
66
export let PathParam = path;
77
export let Body = body(null);
88
export let Query = query(null);
99
export let QueryParam = query;
1010
export let QueryParams = query(null);
11+
export let Observe = observe;
1112

1213
// Headers
1314
export let Headers = headers;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ngx-http-rest",
3-
"version": "0.3.2",
3+
"version": "0.4.0",
44
"devDependencies": {
55
"@angular/http": "^4.0.0",
66
"@angular/core": "^4.0.0",

src/ngx-http-rest.utils.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
import { Injectable } from '@angular/core';
22
import { Observable } from 'rxjs';
33
import { HttpClient, HttpParams, HttpHeaders } from "@angular/common/http";
4+
import { HttpObserve } from "@angular/common/http/src/client";
45

56
interface httpRequestOptions {
67
body?: any;
78
headers?: HttpHeaders;
89
params?: HttpParams;
10+
observe?: HttpObserve;
911
reportProgress?: boolean;
1012
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
1113
withCredentials?: boolean;
1214
}
1315

16+
17+
export function observe(annotations: any) {
18+
return (...args: any[]) => HttpRestUtils.decorate.apply(this, ['observe', annotations, ...args]);
19+
}
1420
export function path(annotations: any) {
1521
return (...args: any[]) => HttpRestUtils.decorate.apply(this, ['path', annotations, ...args]);
1622
}
@@ -103,17 +109,27 @@ export class HttpRestUtils {
103109
const search = HttpRestUtils.collectQueryParams(target, key, args);
104110
const headers = HttpRestUtils.collectHeaders(target, key, args);
105111
const producesType = HttpRestUtils.produce(target, key, args);
112+
const observe = HttpRestUtils.getObserve(target, key, args)
106113
const params: httpRequestOptions = {
107114
body,
108115
params: search,
109116
headers,
110-
responseType: producesType
117+
responseType: producesType,
118+
observe
111119
};
112120
return HttpRestUtils.http.request(requestMethodName, url, params);
113121
};
114122
};
115123
}
116124

125+
private static getObserve(target: any, methodName: string, args: any[]) {
126+
if (target[RESOURSE_METADATA_ROOT].methods
127+
&& target[RESOURSE_METADATA_ROOT].methods[methodName]) {
128+
return target[RESOURSE_METADATA_ROOT].methods[methodName].observe;
129+
}
130+
return undefined;
131+
}
132+
117133
private static produce(target: any, methodName: string, args: any[]) {
118134
if (target[RESOURSE_METADATA_ROOT].methods
119135
&& target[RESOURSE_METADATA_ROOT].methods[methodName]) {

0 commit comments

Comments
 (0)