forked from Ovi/DummyJSON
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs-users.ejs
More file actions
671 lines (621 loc) · 21.7 KB
/
docs-users.ejs
File metadata and controls
671 lines (621 loc) · 21.7 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
<!DOCTYPE html>
<html lang="en">
<!-- header -->
<%- include('./partials/docs-head') %>
<body>
<!-- header -->
<%- include('./partials/header') %>
<!-- side-nav -->
<%- include('./partials/docs-side-nav') %>
<section>
<div class="content">
<h1 class="docs-title">
<img src="/public/img/icons/user.svg" class="icon" alt="svg icon" /> Users - Docs
</h1>
<p class="display-para">
The <strong>users</strong> endpoint provides a versatile dataset of sample user information and related data like carts, posts, and todos, making it ideal for testing and prototyping user management functionalities in web applications. </p>
<div class="resource" id="users-all">
<a href="#users-all" class="res-title">Get all users</a>
<p class="res-desc">
By default you will get 30 items, use <a href="#users-limit_skip">Limit and skip</a> to paginate through all items.
</p>
<pre><code class="language-js">
fetch('https://dummyjson.com/users')
.then(res => res.json())
.then(console.log);
</code></pre>
<button class="show-output btn">Show Output</button>
<pre class="output"><code class="language-json">
{
"users": [
{
"id": 1,
"firstName": "Emily",
"lastName": "Johnson",
"maidenName": "Smith",
"age": 28,
"gender": "female",
"email": "emily.johnson@x.dummyjson.com",
"phone": "+81 965-431-3024",
"username": "emilys",
"password": "emilyspass",
"birthDate": "1996-5-30",
"image": "...",
"bloodGroup": "O-",
"height": 193.24,
"weight": 63.16,
"eyeColor": "Green",
"hair": {
"color": "Brown",
"type": "Curly"
},
"ip": "42.48.100.32",
"address": {
"address": "626 Main Street",
"city": "Phoenix",
"state": "Mississippi",
"stateCode": "MS",
"postalCode": "29112",
"coordinates": {
"lat": -77.16213,
"lng": -92.084824
},
"country": "United States"
},
"macAddress": "47:fa:41:18:ec:eb",
"university": "University of Wisconsin--Madison",
"bank": {
"cardExpire": "03/26",
"cardNumber": "9289760655481815",
"cardType": "Elo",
"currency": "CNY",
"iban": "YPUXISOBI7TTHPK2BR3HAIXL"
},
"company": {
"department": "Engineering",
"name": "Dooley, Kozey and Cronin",
"title": "Sales Manager",
"address": {
"address": "263 Tenth Street",
"city": "San Francisco",
"state": "Wisconsin",
"stateCode": "WI",
"postalCode": "37657",
"coordinates": {
"lat": 71.814525,
"lng": -161.150263
},
"country": "United States"
}
},
"ein": "977-175",
"ssn": "900-590-289",
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36",
"crypto": {
"coin": "Bitcoin",
"wallet": "0xb9fc2fe63b2a6c003f1c324c3bfa53259162181a",
"network": "Ethereum (ERC20)"
},
"role": "admin" // or "moderator", or "user"
},
{...},
{...}
// 30 items
],
"total": 208,
"skip": 0,
"limit": 30
}
</code></pre>
</div>
<div class="resource" id="users-login">
<a href="#users-login" class="res-title">Login user and get tokens</a>
<p class="res-tip">
You can use any user's credentials from <a href="/users">dummyjson.com/users</a>. Tokens are returned in the response and set as cookies.
</p>
<pre><code class="language-js">
fetch('https://dummyjson.com/user/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
<!-- any username/password from users module -->
username: 'emilys',
password: 'emilyspass',
expiresInMins: 30, // optional, defaults to 60
}),
})
.then(res => res.json())
.then(console.log);
</code></pre>
<button class="show-output btn">Show Output</button>
<pre class="output"><code class="language-json">
{
"id": 1,
"username": "emilys",
"email": "emily.johnson@x.dummyjson.com",
"firstName": "Emily",
"lastName": "Johnson",
"gender": "female",
"image": "https://dummyjson.com/icon/emilys/128",
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", // JWT accessToken (for backward compatibility) in response and cookies
"refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." // refreshToken in response and cookies
}
</code></pre>
</div>
<div class="resource" id="users-me">
<a href="#users-me" class="res-title">Get current authenticated user</a>
<p class="res-tip">You can either pass the access token via the Authorization header (JWT) or use cookies for automatic handling.</p>
<pre><code class="language-js">
/* providing access token in bearer */
fetch('https://dummyjson.com/user/me', {
method: 'GET',
headers: {
'Authorization': 'Bearer /* YOUR_ACCESS_TOKEN_HERE */', // Pass JWT via Authorization header
},
credentials: 'include' // Include cookies (e.g., accessToken) in the request
})
.then(res => res.json())
.then(console.log);
</code></pre>
<button class="show-output btn">Show Output</button>
<pre class="output"><code class="language-json">
{
"id": 1,
"firstName": "Emily",
"lastName": "Johnson",
"maidenName": "Smith",
"age": 28,
"gender": "female",
"email": "emily.johnson@x.dummyjson.com",
"image": "...",
/* rest user data */
}
</code></pre>
</div>
<div class="resource" id="users-single">
<a href="#users-single" class="res-title">Get a single user</a>
<pre><code class="language-js">
fetch('https://dummyjson.com/users/1')
.then(res => res.json())
.then(console.log);
</code></pre>
<button class="show-output btn">Show Output</button>
<pre class="output"><code class="language-json">
{
"id": 1,
"firstName": "Emily",
"lastName": "Johnson",
"maidenName": "Smith",
"age": 28,
"gender": "female",
"email": "emily.johnson@x.dummyjson.com",
"phone": "+81 965-431-3024",
"username": "emilys",
"password": "emilyspass",
"birthDate": "1996-5-30",
"image": "...",
"bloodGroup": "O-",
"height": 193.24,
"weight": 63.16,
"eyeColor": "Green",
"hair": {
"color": "Brown",
"type": "Curly"
},
"ip": "42.48.100.32",
"address": {
"address": "626 Main Street",
"city": "Phoenix",
"state": "Mississippi",
"stateCode": "MS",
"postalCode": "29112",
"coordinates": {
"lat": -77.16213,
"lng": -92.084824
},
"country": "United States"
},
"macAddress": "47:fa:41:18:ec:eb",
"university": "University of Wisconsin--Madison",
"bank": {
"cardExpire": "03/26",
"cardNumber": "9289760655481815",
"cardType": "Elo",
"currency": "CNY",
"iban": "YPUXISOBI7TTHPK2BR3HAIXL"
},
"company": {
"department": "Engineering",
"name": "Dooley, Kozey and Cronin",
"title": "Sales Manager",
"address": {
"address": "263 Tenth Street",
"city": "San Francisco",
"state": "Wisconsin",
"stateCode": "WI",
"postalCode": "37657",
"coordinates": {
"lat": 71.814525,
"lng": -161.150263
},
"country": "United States"
}
},
"ein": "977-175",
"ssn": "900-590-289",
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36",
"crypto": {
"coin": "Bitcoin",
"wallet": "0xb9fc2fe63b2a6c003f1c324c3bfa53259162181a",
"network": "Ethereum (ERC20)"
},
"role": "admin" // or "moderator", or "user"
}
</code></pre>
</div>
<div class="resource" id="users-search">
<a href="#users-search" class="res-title">Search users</a>
<pre><code class="language-js">
fetch('https://dummyjson.com/users/search?q=John')
.then(res => res.json())
.then(console.log);
</code></pre>
<button class="show-output btn">Show Output</button>
<pre class="output"><code class="language-json">
{
"users": [
{
"id": 50,
"firstName": "Emily",
"lastName": "Johnson", // name matched the search query
/* rest user data */
},
{...},
{...}
// 3 items
],
"total": 3,
"skip": 0,
"limit": 3
}
</code></pre>
</div>
<div class="resource" id="users-filter">
<a href="#users-filter" class="res-title">Filter users</a>
<p class="res-tip">
You can pass key (nested keys with `.`) and value as params to filter users. (key and value are case-sensitive)
</p>
<p class="res-tip">
`limit`, `skip` and `select` works too.
</p>
<pre><code class="language-js">
fetch('https://dummyjson.com/users/filter?key=hair.color&value=Brown')
.then(res => res.json())
.then(console.log);
</code></pre>
<button class="show-output btn">Show Output</button>
<pre class="output"><code class="language-json">
{
"users": [
{
"firstName": "Emily",
"hair": {
"color": "Brown", // filter matched hair color
type: "Curly"
},
"id": 1,
"lastName": "Johnson"
/* rest user data */
},
{...},
{...}
// 23 items
],
"total": 23,
"skip": 0,
"limit": 23
}
</code></pre>
</div>
<div class="resource" id="users-limit_skip">
<a href="#users-limit_skip" class="res-title">Limit and skip users</a>
<p class="res-tip">
You can pass `limit` and `skip` params to limit and skip the
results for pagination, and use `limit=0` to get all items.
</p>
<p class="res-tip">
You can pass `select` as query params with comma-separated values
to select specific data
</p>
<pre><code class="language-js">
fetch('https://dummyjson.com/users?limit=5&skip=10&select=firstName,age')
.then(res => res.json())
.then(console.log);
</code></pre>
<button class="show-output btn">Show Output</button>
<pre class="output"><code class="language-json">
{
"users": [
{
"id": 11, // 10 items were skipped
"firstName": "Liam",
"age": 29
},
{
"id": 12,
"firstName": "Mia",
"age": 24
},
{
"id": 13,
"firstName": "Noah",
"age": 40
},
{
"id": 14,
"firstName": "Charlotte",
"age": 36
},
{
"id": 15,
"firstName": "William",
"age": 32
}
],
"total": 208,
"skip": 10, // 10 items were skipped
"limit": 5 // limit was applied
}
</code></pre>
</div>
<div class="resource" id="users-sort">
<a href="#users-sort" class="res-title">Limit and skip users</a>
<p class="res-tip">
You can pass `sortBy` and `order` params to sort the results,
`sortBy` should be field name and `order` should be "asc" or "desc"
</p>
<pre><code class="language-js">
fetch('https://dummyjson.com/users?sortBy=firstName&order=asc')
.then(res => res.json())
.then(console.log);
</code></pre>
<button class="show-output btn">Show Output</button>
<pre class="output"><code class="language-json">
{
"users": [
{
"id": 84,
"firstName": "Aaliyah", // sorted by firstName in ascending order
"lastName": "Hanson",
"maidenName": ""
/* rest user data */
},
{
"id": 176,
"firstName": "Aaliyah", // sorted by firstName in ascending order
"lastName": "Martinez",
"maidenName": "Adams"
/* rest user data */
},
{...}
// 30 items
],
"total": 208,
"skip": 0,
"limit": 30
}
</code></pre>
</div>
<div class="resource" id="users-carts">
<a href="#users-carts" class="res-title">Get user's carts by user id</a>
<pre><code class="language-js">
/* getting carts of user with id 6 */
fetch('https://dummyjson.com/users/6/carts')
.then(res => res.json())
.then(console.log);
</code></pre>
<button class="show-output btn">Show Output</button>
<pre class="output"><code class="language-json">
{
"carts": [
{
"id": 24,
"products": [
{
"id": 108,
"title": "iPhone 12 Silicone Case with MagSafe Plum",
"price": 29.99,
"quantity": 5,
"total": 149.95,
"discountPercentage": 14.68,
"discountedTotal": 127.94,
"thumbnail": "..."
},
{...},
{...}
],
"total": 1749.9,
"discountedTotal": 1594.33,
"userId": 6, // user id is 6
"totalProducts": 3,
"totalQuantity": 10
}
],
"total": 1,
"skip": 0,
"limit": 1
}
</code></pre>
</div>
<div class="resource" id="users-posts">
<a href="#users-posts" class="res-title">Get user's posts by user id</a>
<pre><code class="language-js">
/* getting posts of user with id 5 */
fetch('https://dummyjson.com/users/5/posts')
.then(res => res.json())
.then(console.log);
</code></pre>
<button class="show-output btn">Show Output</button>
<pre class="output"><code class="language-json">
{
"posts": [
{
"id": 61,
"title": "I'm going to hire professional help tomorrow.",
"body": "I'm going to hire professional help tomorrow. /*... more data */ ",
"userId": 5, // user id is 5
"tags": [
"fiction"
"classic"
"american"
],
"reactions": {
"likes": 1127,
"dislikes": 40
}
},
{...}
],
"total": 2,
"skip": 0,
"limit": 2
}
</code></pre>
</div>
<div class="resource" id="users-todos">
<a href="#users-todos" class="res-title">Get user's todos by user id</a>
<pre><code class="language-js">
/* getting todos of user with id 5 */
fetch('https://dummyjson.com/users/5/todos')
.then(res => res.json())
.then(console.log);
</code></pre>
<button class="show-output btn">Show Output</button>
<pre class="output"><code class="language-json">
{
"todos": [
{
"id": 19,
"todo": "Create a compost pile",
"completed": true,
"userId": 5 // user id is 5
},
{
"id": 85,
"todo": "Make a budget",
"completed": true,
"userId": 5
},
{
"id": 103,
"todo": "Go to a local thrift shop",
"completed": true,
"userId": 5
}
],
"total": 3,
"skip": 0,
"limit": 3
}
</code></pre>
</div>
<div class="resource" id="users-add">
<a href="#users-add" class="res-title">Add a new user</a>
<p class="res-tip">
Adding a new user will not add it into the server.
<br />
It will simulate a POST request and will return the new created user with a new id
</p>
<pre><code class="language-js">
fetch('https://dummyjson.com/users/add', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
firstName: 'Muhammad',
lastName: 'Ovi',
age: 250,
/* other user data */
})
})
.then(res => res.json())
.then(console.log);
</code></pre>
<button class="show-output btn">Show Output</button>
<pre class="output"><code class="language-json">
{
"id": 209,
"firstName": "Muhammad",
"lastName": "Ovi",
"age": 250,
/* rest user data */
}
</code></pre>
</div>
<div class="resource" id="users-update">
<a href="#users-update" class="res-title">Update a user</a>
<p class="res-tip">
Updating a user will not update it into the server.
<br />
It will simulate a PUT/PATCH request and will return updated user with modified data
</p>
<pre><code class="language-js">
/* updating lastName of user with id 2 */
fetch('https://dummyjson.com/users/2', {
method: 'PUT', /* or PATCH */
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
lastName: 'Owais'
})
})
.then(res => res.json())
.then(console.log);
</code></pre>
<button class="show-output btn">Show Output</button>
<pre class="output"><code class="language-json">
{
"id": "2",
"firstName": "Michael",
"lastName": "Owais", // only lastName is updated
"gender": "male",
/* other user data */
}
</code></pre>
</div>
<div class="resource" id="users-delete">
<a href="#users-delete" class="res-title">Delete a user</a>
<p class="res-tip">
Deleting a user will not delete it into the server.
<br />
It will simulate a DELETE request and will return deleted user with `isDeleted` & `deletedOn` keys
</p>
<pre><code class="language-js">
fetch('https://dummyjson.com/users/1', {
method: 'DELETE',
})
.then(res => res.json())
.then(console.log);
</code></pre>
<button class="show-output btn">Show Output</button>
<pre class="output"><code class="language-json">
{
"id": 1,
"firstName": "Emily",
"lastName": "Johnson",
"maidenName": "Smith",
"age": 28,
"gender": "female",
/* other user data */
"isDeleted": true,
"deletedOn": /* ISOTime */
}
</code></pre>
</div>
</div>
</section>
<!-- footer -->
<%- include('./partials/docs-footer') %>
<script>
selectNavItem(window.location.hash || '#users-all');
</script>
</body>
</html>