Skip to content

Commit

Permalink
feat(AjaxObservable) : support 'PATCH' request type
Browse files Browse the repository at this point in the history
Add support of the 'PATCH' request type based on the already existing 'PUT' request.
  • Loading branch information
herflis committed Feb 10, 2017
1 parent 31dfc73 commit 46c954a
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/observable/dom/AjaxObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export interface AjaxCreationMethod {
get(url: string, headers?: Object): Observable<AjaxResponse>;
post(url: string, body?: any, headers?: Object): Observable<AjaxResponse>;
put(url: string, body?: any, headers?: Object): Observable<AjaxResponse>;
patch(url: string, body?: any, headers?: Object): Observable<AjaxResponse>;
delete(url: string, headers?: Object): Observable<AjaxResponse>;
getJSON<T>(url: string, headers?: Object): Observable<T>;
}
Expand All @@ -86,6 +87,10 @@ export function ajaxPut(url: string, body?: any, headers?: Object): Observable<A
return new AjaxObservable<AjaxResponse>({ method: 'PUT', url, body, headers });
};

export function ajaxPatch(url: string, body?: any, headers?: Object): Observable<AjaxResponse> {
return new AjaxObservable<AjaxResponse>({ method: 'PATCH', url, body, headers });
};

export function ajaxGetJSON<T>(url: string, headers?: Object): Observable<T> {
return new AjaxObservable<AjaxResponse>({ method: 'GET', url, responseType: 'json', headers })
.lift<T>(new MapOperator<AjaxResponse, T>((x: AjaxResponse, index: number): T => x.response, null));
Expand Down Expand Up @@ -132,6 +137,7 @@ export class AjaxObservable<T> extends Observable<T> {
create.post = ajaxPost;
create.delete = ajaxDelete;
create.put = ajaxPut;
create.patch = ajaxPatch;
create.getJSON = ajaxGetJSON;

return <AjaxCreationMethod>create;
Expand Down

0 comments on commit 46c954a

Please sign in to comment.