Advertisement
Shell_Casing

service

Dec 12th, 2018
596
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. import { Injectable } from '@angular/core';
  2. import { HttpClient } from '@angular/common/http';
  3.  
  4. @Injectable({
  5. providedIn: 'root'
  6. })
  7. export class ArticleService {
  8.  
  9. serverUrl = 'http://127.0.0.1:3000/articles';
  10.  
  11. constructor(private http: HttpClient) { }
  12.  
  13.  
  14. getAllArticles() {
  15. return this.http.get(this.serverUrl);
  16. }
  17.  
  18.  
  19. getOneArticle(id) {
  20. return this.http.get(`${this.serverUrl}/${id}`);
  21. }
  22.  
  23.  
  24. addArticle(title, content) {
  25. const article = { title: title, content: content };
  26. return this.http.post(`${this.serverUrl}/add`, article);
  27. }
  28.  
  29.  
  30. updateArticle(id, title, content) {
  31. const article = { title: title, content: content };
  32. return this.http.put(`${this.serverUrl}/update/${id}`, article);
  33. }
  34.  
  35.  
  36. deleteArticle(id) {
  37. return this.http.delete(`${this.serverUrl}/delete/${id}`);
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement