Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

posts-service.ts

21 lines495 Bytes

1import { HttpClient } from '@angular/common/http'
2import { Injectable, inject } from '@angular/core'
3​
4@Injectable({
5 providedIn: 'root',
6})
7export class PostsService {
8 readonly #http = inject(HttpClient)
9​
10 postById$ = (postId: number) =>
11 this.#http.get<Post>(`https://jsonplaceholder.typicode.com/posts/${postId}`)
12​
13 allPosts$ = () =>
14 this.#http.get<Array<Post>>('https://jsonplaceholder.typicode.com/posts')
16​
17export interface Post {
18 id: number
19 title: string
20 body: string