Skip to content

Instantly share code, notes, and snippets.

@mkubdev
Created October 21, 2020 09:37
Show Gist options
  • Select an option

  • Save mkubdev/2361d88c7aa0a086505836b413732c4d to your computer and use it in GitHub Desktop.

Select an option

Save mkubdev/2361d88c7aa0a086505836b413732c4d to your computer and use it in GitHub Desktop.
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from '../src/environments/environment';
import { map } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class PostService {
constructor(private http: HttpClient) { }
getAllPosts() {
return this.http.get(`${environment.apiUrl}/posts`).pipe(map(res => res));
}
getPost(postId) {
return this.http.get(`${environment.apiUrl}/posts/${postId}`).pipe(map(res => res));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment