Improve Http Request

This commit is contained in:
kevinpauer
2022-03-28 00:37:49 +02:00
parent 0393f153bf
commit e9f1e7d38a
8 changed files with 102 additions and 27 deletions

View File

@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { Injectable, OnInit } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
import { delay, Observable } from 'rxjs';
import { TokenStorageService } from './token.service';
const API_URL = 'https://aktienbot.flokaiser.com/api/';
@Injectable({
@@ -12,26 +12,32 @@ export class DataService {
private tokenStorage: TokenStorageService
) {}
headers = new HttpHeaders({
'Content-Type': 'application/json',
Authorization: 'Bearer ' + this.tokenStorage.getToken(),
});
async getStockData() {
await this.http
.get(API_URL + 'portfolio', {
headers: this.headers,
responseType: 'text',
})
.subscribe((data) => {
console.log(data);
return data;
});
public getStockData(): Observable<any> {
return this.http.get(API_URL + 'portfolio', {
headers: new HttpHeaders({
'Content-Type': 'application/json',
Authorization: 'Bearer ' + this.tokenStorage.getToken(),
}),
responseType: 'text',
});
}
getKeywords(): Observable<any> {
public getTransactionData(): Observable<any> {
return this.http.get(API_URL + 'transactions', {
headers: new HttpHeaders({
'Content-Type': 'application/json',
Authorization: 'Bearer ' + this.tokenStorage.getToken(),
}),
responseType: 'text',
});
}
public getKeywords(): Observable<any> {
return this.http.get(API_URL + 'keywords', {
headers: this.headers,
headers: new HttpHeaders({
'Content-Type': 'application/json',
Authorization: 'Bearer ' + this.tokenStorage.getToken(),
}),
responseType: 'text',
});
}