Created
February 10, 2018 18:15
-
-
Save Frelseren/ed264ee1c0ecb9d65c370f9e9e7342bf to your computer and use it in GitHub Desktop.
Angular service for Apex requests
This file contains hidden or 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
// apex.service.ts | |
import { Injectable } from '@angular/core'; | |
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; | |
import { Observable } from 'rxjs/Observable'; | |
declare const sessionId; | |
interface Contact { | |
Id: string; | |
Name: string; | |
Title: string; | |
Phone: string; | |
Email: string; | |
} | |
@Injectable() | |
export class ApexService { | |
headers = new HttpHeaders({ 'Authorization': 'Bearer ' + sessionId }); | |
constructor( | |
private http: HttpClient | |
) { } | |
get(contactId?: string): Observable<Contact[]> { | |
const params = new HttpParams().set('contactId', contactId); | |
return this.http.get<Contact[]>('/services/apexrest/angularpoc', { | |
headers: this.headers, | |
params: contactId ? params : null | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment