I've created an Angular service to handle all the HTTP requests necessary for my controllers to communicate with my API.
export interface IDummyEntityApiService {
getAllDummies() : ng.IPromise<Array<Entities.IDummy>>;
}
class DummyEntityApiService implements IDummyEntityApiService {
private http: ng.IHttpService;
constructor($http : ng.IHttpService) {
this.http = $http;
}
getAllDummies() {
var url = "acme.com/api/dummies";
return this.http.get(url).then(result => {
return result.data;
}, error => {
// log error
});
}
}
This service can be used as follows:
dummyEntityApiService.getAllDummies.then(result => {
// fill results into list
}, error => {
fancyToast.create("Ooops, something went wrong: " + error);
});
Now, I'm wondering how to implement the POST
and DELETE
functionalities. I am aware that the $httpService
has methods like .post(url, data)
and .delete(url)
, which both return IHttpPromise<{}>
. However, casting them up to a IPromise
doesn't seem logical since there is no data that needs to be resolved in these cases?