-
-
Notifications
You must be signed in to change notification settings - Fork 753
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for @angular/common/http (HttpClient) (#2)
* add .idea/ to .gitignore * add support for @angular/common/http (HttpClient)
- Loading branch information
Showing
6 changed files
with
210 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,4 @@ node_modules | |
.lock-wscript | ||
|
||
dist/ | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const Base = require('./base'); | ||
|
||
class AngularHttpService extends Base { | ||
request (options) { | ||
const httpClient = this.connection; | ||
const HttpHeaders = this.options.HttpHeaders; | ||
|
||
if (!httpClient || !HttpHeaders) { | ||
throw new Error(`Please pass angular's 'httpClient' (instance) and and object with 'HttpHeaders' (class) to feathers-rest`); | ||
} | ||
|
||
const url = options.url; | ||
const requestOptions = { | ||
// method: options.method, | ||
body: options.body, | ||
headers: new HttpHeaders( | ||
Object.assign( | ||
{Accept: 'application/json'}, | ||
this.options.headers, | ||
options.headers | ||
) | ||
) | ||
}; | ||
|
||
return new Promise((resolve, reject) => { | ||
httpClient.request(options.method, url, requestOptions) | ||
.subscribe(resolve, reject); | ||
}) | ||
.catch(error => { | ||
throw error.error || error; | ||
}); | ||
} | ||
} | ||
|
||
module.exports = AngularHttpService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.