Skip to content

Instantly share code, notes, and snippets.

@Frelseren
Created February 10, 2018 18:15
Show Gist options
  • Save Frelseren/ed264ee1c0ecb9d65c370f9e9e7342bf to your computer and use it in GitHub Desktop.
Save Frelseren/ed264ee1c0ecb9d65c370f9e9e7342bf to your computer and use it in GitHub Desktop.
Angular service for Apex requests
// 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