What is the best way to make requests?
I have an http request
method in project.service.ts
. I can make the request with the following structure:
getProjectById(projectId: number) {
return this.http.get<Project>(`${this.url}/search/projects/${projectId}`).toPromise();
}
And call it with the following structure in project.component.ts
:
async getProject(projectId: number) {
this.isLoading = true;
try {
this.project = await this.api.projects.getProjectById(projectId);
} finally {
this.isLoading = true;
}
}
But I can also make the request like this:
async getProjectById(projectId: number) {
return await this.http.get<Project>(`${this.url}/search/projects/${projectId}`).toPromise();
}
Or this:
getProjectById(projectId: number): Observable<Project> {
return this.http.get<Project>(`${this.url}/search/project/${projectId}`);
}
But I'd have to subscribe
to this function.