parent
6934dddda4
commit
70914dddba
@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { UserService } from './user.service';
|
||||
|
||||
describe('UserService', () => {
|
||||
let service: UserService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(UserService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
@ -0,0 +1,26 @@
|
||||
import { Injectable, OnInit } from '@angular/core';
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
import { environment } from '../../../environments/environment';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class UserService {
|
||||
|
||||
private apiURL = environment.apiURL;
|
||||
constructor(private http: HttpClient) {
|
||||
}
|
||||
|
||||
getUser(username:string) {
|
||||
const url = `${this.apiURL}/users`;
|
||||
const headers = new HttpHeaders({
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: 'Bearer ' + localStorage.getItem('auth_token'),
|
||||
});
|
||||
const params = { name : username };
|
||||
|
||||
return this.http.get<any[]>(url,{ headers:headers, params:params })
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in new issue