-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfork.js
More file actions
40 lines (30 loc) · 732 Bytes
/
Copy pathfork.js
File metadata and controls
40 lines (30 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const Url = require('../lib')
const Api = Url('https://my-json-server.typicode.com')
.go('typicode', 'demo')
const Posts = Api
.fork()
.go('posts')
const Comments = Api
.fork()
.go('comments')
const Post = (id) => Posts
.fork()
.go(id)
const apis = [ Posts, Post(2), Comments ]
for (let index = 0; index < apis.length; index++) {
const api = apis[index]
api
.get()
.then(response => console.log(response, '\n'))
.catch(err => console.log(err))
}
// [
// { id: 1, title: 'Post 1' },
// { id: 2, title: 'Post 2' },
// { id: 3, title: 'Post 3' }
// ]
// { id: 2, title: 'Post 2' }
// [
// { id: 1, body: 'some comment', postId: 1 },
// { id: 2, body: 'some comment', postId: 1 }
// ]