forked from devos-quickstarter/ansible-quickstarter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_test.json
805 lines (805 loc) · 27.2 KB
/
api_test.json
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
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
{
"info": {
"_postman_id": "dbee707b-e6d8-4218-b8ae-9c0495fbc67c",
"name": "Postman Tests Mock",
"description": "This collection contains examples of tests that you can use to automate your testing process.\n\n- Basic test syntax\n- API tests\n- Integration tests\n\n# Quick tips for writing tests\n- Organize your test scenarios by grouping your requests in [collections](https://www.getpostman.com/docs/v6/postman/collections/intro_to_collections) and [folders](https://www.getpostman.com/docs/v6/postman/collections/managing_collections#adding-folders), and naming them descriptively\n- Document your API’s requirements using [markdown in the descriptions](https://www.getpostman.com/docs/v6/postman/collections/using_markdown_for_descriptions)\n- Use [variables](https://www.getpostman.com/docs/v6/postman/environments_and_globals/variables) to simulate more sophisticated user flows\n- Common tests that will be run after every request can be added to collection-level tests or folder-level tests\n\n# Resources\nIf you're not already familiar with writing tests in Postman, check out these resources.\n* Postman docs: [Test scripts](https://www.getpostman.com/docs/v6/postman/scripts/test_scripts)\n* Postman docs: [Test examples](https://www.getpostman.com/docs/v6/postman/scripts/test_examples)\n* Community contribution: [Quick reference guide](https://community.getpostman.com/t/the-postman-cheatsheet-quick-reference-guide/1054)\n* Community contribution: [Examples and guides](https://github.com/DannyDainton/All-Things-Postman)\n* Postman blog: [Writing tests in Postman](http://blog.getpostman.com/2017/10/25/writing-tests-in-postman/)\n* Postman blog: [API testing tips from a Postman professional](http://blog.getpostman.com/2017/07/28/api-testing-tips-from-a-postman-professional/)",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Basic test syntax",
"item": [
{
"name": "pm.test",
"event": [
{
"listen": "test",
"script": {
"exec": [
"// use the `pm.*` API to write your test",
"// the `pm.test()` method accepts 2 parameters",
"// the first parameter is the name of your test (be descriptive)",
"// the second parameter is a function whereby if any assertions within your function fail, then the test will fail",
"",
"pm.test(\"Name of the first test\", function () {",
" // make an assertion",
" // if your assertion throws an error, this test will fail",
" pm.response.to.have.status(200);",
"});",
"",
"pm.test(\"Name of the second test\", function () {",
" // make as many assertions as you'd like as part of this test",
" // if any assertion throws an error, this test will fail",
" pm.response.to.have.status(200);",
" pm.response.to.be.ok;",
" pm.response.to.be.json;",
"});",
""
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://postman-echo.com/get?foo1=bar1&foo2=bar2",
"protocol": "https",
"host": [
"postman-echo",
"com"
],
"path": [
"get"
],
"query": [
{
"key": "foo1",
"value": "bar1"
},
{
"key": "foo2",
"value": "bar2"
}
]
},
"description": "In the Postman app, review the tests written under the **Tests** tab in the request builder on the top. Send this request, and view the results of the tests under the **Tests** tab in the response viewer on the bottom.\n\n### The `pm.*` API\n\nUse the `pm.*` API to write your test under the **Tests** tab in Postman. The `pm.test()` method accepts 2 parameters. The first parameter is the name of the test, so it's important to give your test a descriptive name to provide more information in case the test fails. The second parameter is a function whereby if any assertions within your function fail, then the test will fail.\n\n```\npm.test(\"Name of the second test\", function () {\n // make as many assertions as you'd like as part of this test\n // if any assertion throws an error, this test will fail\n pm.response.to.have.status(200);\n pm.response.to.be.ok;\n pm.response.to.be.json;\n});\n```"
},
"response": [
{
"name": "Status",
"originalRequest": {
"method": "GET",
"header": [],
"url": {
"raw": "https://postman-echo.com/get?foo1=bar1&foo2=bar2",
"protocol": "https",
"host": [
"postman-echo",
"com"
],
"path": [
"get"
],
"query": [
{
"key": "foo1",
"value": "bar1"
},
{
"key": "foo2",
"value": "bar2"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Encoding",
"value": "gzip"
},
{
"key": "Content-Type",
"value": "application/json; charset=utf-8"
},
{
"key": "Date",
"value": "Thu, 15 Nov 2018 22:21:20 GMT"
},
{
"key": "ETag",
"value": "W/\"1cd-LkUKVugbVYQuMcTU7OTzmp77cMo\""
},
{
"key": "Server",
"value": "nginx"
},
{
"key": "Vary",
"value": "Accept-Encoding"
},
{
"key": "Content-Length",
"value": "348"
},
{
"key": "Connection",
"value": "keep-alive"
}
],
"cookie": [],
"body": "{\n \"args\": {\n \"foo1\": \"bar1\",\n \"foo2\": \"bar2\"\n },\n \"headers\": {\n \"x-forwarded-proto\": \"https\",\n \"host\": \"postman-echo.com\",\n \"accept\": \"*/*\",\n \"accept-encoding\": \"gzip, deflate\",\n \"cache-control\": \"no-cache\",\n \"cookie\": \"sails.sid=s%3AK8csWt5VZ3Oalv85HiBtffDcrSOJ-RiP.V14RjjJqkOv8%2BLXuHRmZ9l50G8S6eU16yLU%2F3N%2F0dKU\",\n \"postman-token\": \"c6b9bca5-7369-4da8-a539-6c906d1133f2\",\n \"user-agent\": \"PostmanRuntime/7.3.0\",\n \"x-forwarded-port\": \"443\"\n },\n \"url\": \"https://postman-echo.com/get?foo1=bar1&foo2=bar2\"\n}"
}
]
}
],
"description": "Oh goody. Did you ever think you would get so excited to read this section title?\n\nThe [Postman Sandbox](https://www.getpostman.com/docs/v6/postman/scripts/postman_sandbox) is a JavaScript execution environment that is accessible during pre-request scripts and test scripts. Whatever code you write under the pre-request and test tabs is executed in this sandbox.\n\nAny code that you write under the **Tests** tab in the Postman app will execute after your request. Consequently you have access to the `pm.response` object to make assertions against the actual response -- this is what we call a Postman test.\n\nReview the example tests under the **Tests** tab in the Postman app.\n\n> **Quick tips for syntax**\n- Give each test a descriptive name. When the test fails, this will provide context to the error.\n- Use `pm.response()` as your base assertion where possible to provide more descriptive error messages.\n- Use the optional 2nd parameter in `pm.expect()` to create custom error messages.",
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
]
},
{
"name": "API tests",
"item": [
{
"name": "Status",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"response is ok\", function () {",
" pm.response.to.have.status(200);",
"});",
""
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://postman-echo.com/get?foo1=bar1&foo2=bar2",
"protocol": "https",
"host": [
"postman-echo",
"com"
],
"path": [
"get"
],
"query": [
{
"key": "foo1",
"value": "bar1"
},
{
"key": "foo2",
"value": "bar2"
}
]
},
"description": "This test is to validate the response status code. This SNIPPET is also available on the right sidebar under `Status code: Code in 200`."
},
"response": [
{
"name": "Status",
"originalRequest": {
"method": "GET",
"header": [],
"url": {
"raw": "https://postman-echo.com/get?foo1=bar1&foo2=bar2",
"protocol": "https",
"host": [
"postman-echo",
"com"
],
"path": [
"get"
],
"query": [
{
"key": "foo1",
"value": "bar1"
},
{
"key": "foo2",
"value": "bar2"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Encoding",
"value": "gzip"
},
{
"key": "Content-Type",
"value": "application/json; charset=utf-8"
},
{
"key": "Date",
"value": "Thu, 15 Nov 2018 22:21:20 GMT"
},
{
"key": "ETag",
"value": "W/\"1cd-LkUKVugbVYQuMcTU7OTzmp77cMo\""
},
{
"key": "Server",
"value": "nginx"
},
{
"key": "Vary",
"value": "Accept-Encoding"
},
{
"key": "Content-Length",
"value": "348"
},
{
"key": "Connection",
"value": "keep-alive"
}
],
"cookie": [],
"body": "{\n \"args\": {\n \"foo1\": \"bar1\",\n \"foo2\": \"bar2\"\n },\n \"headers\": {\n \"x-forwarded-proto\": \"https\",\n \"host\": \"postman-echo.com\",\n \"accept\": \"*/*\",\n \"accept-encoding\": \"gzip, deflate\",\n \"cache-control\": \"no-cache\",\n \"cookie\": \"sails.sid=s%3AK8csWt5VZ3Oalv85HiBtffDcrSOJ-RiP.V14RjjJqkOv8%2BLXuHRmZ9l50G8S6eU16yLU%2F3N%2F0dKU\",\n \"postman-token\": \"c6b9bca5-7369-4da8-a539-6c906d1133f2\",\n \"user-agent\": \"PostmanRuntime/7.3.0\",\n \"x-forwarded-port\": \"443\"\n },\n \"url\": \"https://postman-echo.com/get?foo1=bar1&foo2=bar2\"\n}"
}
]
},
{
"name": "Data type",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Content-Type is present\", function () {",
" pm.response.to.have.header(\"Content-Type\");",
"});",
"",
"pm.test(\"Content-Type is JSON\", function () {",
" pm.response.to.be.json;",
"})"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "PATCH",
"header": [],
"body": {
"mode": "raw",
"raw": "This is expected to be sent back as part of response body."
},
"url": {
"raw": "https://postman-echo.com/patch",
"protocol": "https",
"host": [
"postman-echo",
"com"
],
"path": [
"patch"
]
},
"description": "This test is to validate the content type of the returned content. This SNIPPET is also available on the right sidebar under `Response headers: Content-Type header check`."
},
"response": [
{
"name": "Data type",
"originalRequest": {
"method": "PATCH",
"header": [],
"body": {
"mode": "raw",
"raw": "This is expected to be sent back as part of response body."
},
"url": {
"raw": "https://postman-echo.com/patch",
"protocol": "https",
"host": [
"postman-echo",
"com"
],
"path": [
"patch"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Encoding",
"value": "gzip"
},
{
"key": "Content-Type",
"value": "application/json; charset=utf-8"
},
{
"key": "Date",
"value": "Thu, 15 Nov 2018 22:21:46 GMT"
},
{
"key": "ETag",
"value": "W/\"237-50TomUYGT9/V9ahCSqZGYpnnS48\""
},
{
"key": "Server",
"value": "nginx"
},
{
"key": "Vary",
"value": "Accept-Encoding"
},
{
"key": "Content-Length",
"value": "410"
},
{
"key": "Connection",
"value": "keep-alive"
}
],
"cookie": [],
"body": "{\n \"args\": {},\n \"data\": \"This is expected to be sent back as part of response body.\",\n \"files\": {},\n \"form\": {},\n \"headers\": {\n \"x-forwarded-proto\": \"https\",\n \"host\": \"postman-echo.com\",\n \"content-length\": \"58\",\n \"accept\": \"*/*\",\n \"accept-encoding\": \"gzip, deflate\",\n \"cache-control\": \"no-cache\",\n \"content-type\": \"text/plain\",\n \"cookie\": \"sails.sid=s%3AUuE9kqyAFxbvBvvH8aX3WEBLXiNgjK7-.ErzxoeVFY7HfTK%2BPjoOs%2BzaP3yU8%2BcM59adz0oo9LlA\",\n \"postman-token\": \"ebd30dd5-0044-4665-ae5c-cb31118f1119\",\n \"user-agent\": \"PostmanRuntime/7.3.0\",\n \"x-forwarded-port\": \"443\"\n },\n \"json\": null,\n \"url\": \"https://postman-echo.com/patch\"\n}"
}
]
},
{
"name": "Functional",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Returns 7 char alphanumeric id\", function () {",
" let jsonData = pm.response.json();",
" pm.expect(jsonData.form.someHash).to.match(/^[a-z0-9]{7}$/);",
"});",
"",
"pm.test(\"Returns 15 char alhpanumeric id\", function () {",
" let jsonData = pm.response.json();",
" pm.expect(jsonData.form.secondHash).to.match(/^[a-z0-9]{15}$/);",
"});",
""
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "someHash",
"value": "7654321",
"type": "text"
},
{
"key": "secondHash",
"value": "987654321asdfgh",
"type": "text"
}
]
},
"url": {
"raw": "https://postman-echo.com/post",
"protocol": "https",
"host": [
"postman-echo",
"com"
],
"path": [
"post"
]
},
"description": "This test is written to validate the server performed a function as expected."
},
"response": [
{
"name": "Functional",
"originalRequest": {
"method": "POST",
"header": [],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "someHash",
"value": "7654321",
"type": "text"
},
{
"key": "secondHash",
"value": "987654321asdfgh",
"type": "text"
}
]
},
"url": {
"raw": "https://postman-echo.com/post",
"protocol": "https",
"host": [
"postman-echo",
"com"
],
"path": [
"post"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Encoding",
"value": "gzip"
},
{
"key": "Content-Type",
"value": "application/json; charset=utf-8"
},
{
"key": "Date",
"value": "Thu, 15 Nov 2018 22:22:08 GMT"
},
{
"key": "ETag",
"value": "W/\"277-9d2jX3MwxfNYN4a9mHbeHYeuEMA\""
},
{
"key": "Server",
"value": "nginx"
},
{
"key": "set-cookie",
"value": "sails.sid=s%3AG3Skk-KwKzhuN9bCFLG38XDvX_n76FY7.SnEQNLnssVB0vIWq0%2Bqn%2FoZhMdvJqAp6Toc8YMDlMhw; Path=/; HttpOnly"
},
{
"key": "Vary",
"value": "Accept-Encoding"
},
{
"key": "Content-Length",
"value": "408"
},
{
"key": "Connection",
"value": "keep-alive"
}
],
"cookie": [],
"body": "{\n \"args\": {},\n \"data\": \"\",\n \"files\": {},\n \"form\": {\n \"someHash\": \"7654321\",\n \"secondHash\": \"987654321asdfgh\"\n },\n \"headers\": {\n \"x-forwarded-proto\": \"https\",\n \"host\": \"postman-echo.com\",\n \"content-length\": \"43\",\n \"accept\": \"*/*\",\n \"accept-encoding\": \"gzip, deflate\",\n \"cache-control\": \"no-cache\",\n \"content-type\": \"application/x-www-form-urlencoded\",\n \"cookie\": \"sails.sid=s%3AUuE9kqyAFxbvBvvH8aX3WEBLXiNgjK7-.ErzxoeVFY7HfTK%2BPjoOs%2BzaP3yU8%2BcM59adz0oo9LlA\",\n \"postman-token\": \"e6a118ae-af47-4fb6-ac35-3cf2bcbafd00\",\n \"user-agent\": \"PostmanRuntime/7.3.0\",\n \"x-forwarded-port\": \"443\"\n },\n \"json\": {\n \"someHash\": \"7654321\",\n \"secondHash\": \"987654321asdfgh\"\n },\n \"url\": \"https://postman-echo.com/post\"\n}"
}
]
},
{
"name": "Functional2",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"response is ok\", function () {",
" pm.response.to.have.status(200);",
"});",
"",
"let jsonResponse = pm.response.json();",
"",
"pm.test(\"Response should be a parsable JSON\", function() {",
" pm.expect(jsonResponse).to.be.ok;",
"});",
"",
"pm.test(\"Response body should be an object\", function() {",
" pm.expect(jsonResponse).to.be.an('object');",
"});",
"",
"pm.test(\"Response body should be in the correct format\", function() {",
" pm.expect(jsonResponse.args).to.be.a('object');",
" pm.expect(jsonResponse.data).to.be.a('string');",
" pm.expect(jsonResponse.files).to.be.a('object');",
" pm.expect(jsonResponse.form).to.be.a('object');",
" pm.expect(jsonResponse.headers).to.be.a('object');",
"});",
"",
""
],
"type": "text/javascript"
}
}
],
"request": {
"method": "DELETE",
"header": [],
"body": {
"mode": "raw",
"raw": "This is expected to be sent back as part of response body."
},
"url": {
"raw": "https://postman-echo.com/delete",
"protocol": "https",
"host": [
"postman-echo",
"com"
],
"path": [
"delete"
]
},
"description": "Another example of bundling several assertions within a single test, and also of bundling several tests within a try-catch code block."
},
"response": [
{
"name": "Functional2",
"originalRequest": {
"method": "DELETE",
"header": [],
"body": {
"mode": "raw",
"raw": "This is expected to be sent back as part of response body."
},
"url": {
"raw": "https://postman-echo.com/delete",
"protocol": "https",
"host": [
"postman-echo",
"com"
],
"path": [
"delete"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Encoding",
"value": "gzip"
},
{
"key": "Content-Type",
"value": "application/json; charset=utf-8"
},
{
"key": "Date",
"value": "Thu, 15 Nov 2018 22:22:22 GMT"
},
{
"key": "ETag",
"value": "W/\"236-unqr/LuiPP07B85WHuciASf+YdA\""
},
{
"key": "Server",
"value": "nginx"
},
{
"key": "set-cookie",
"value": "sails.sid=s%3Aa9JaDxhKoLl3zyptDL3Vbo-kXgiIoqOY.o566AhO0IGGXbdop127kZi0Xq9bHd0q3RjrHgs2G9c4; Path=/; HttpOnly"
},
{
"key": "Vary",
"value": "Accept-Encoding"
},
{
"key": "Content-Length",
"value": "415"
},
{
"key": "Connection",
"value": "keep-alive"
}
],
"cookie": [],
"body": "{\n \"args\": {},\n \"data\": \"This is expected to be sent back as part of response body.\",\n \"files\": {},\n \"form\": {},\n \"headers\": {\n \"x-forwarded-proto\": \"https\",\n \"host\": \"postman-echo.com\",\n \"content-length\": \"58\",\n \"accept\": \"*/*\",\n \"accept-encoding\": \"gzip, deflate\",\n \"cache-control\": \"no-cache\",\n \"content-type\": \"text/plain\",\n \"cookie\": \"sails.sid=s%3AG3Skk-KwKzhuN9bCFLG38XDvX_n76FY7.SnEQNLnssVB0vIWq0%2Bqn%2FoZhMdvJqAp6Toc8YMDlMhw\",\n \"postman-token\": \"a26a6cbb-abb4-4e8b-8a1e-4ba63450afcb\",\n \"user-agent\": \"PostmanRuntime/7.3.0\",\n \"x-forwarded-port\": \"443\"\n },\n \"json\": null,\n \"url\": \"https://postman-echo.com/delete\"\n}"
}
]
},
{
"name": "JSON schema v4 validation",
"event": [
{
"listen": "test",
"script": {
"exec": [
"var schema = {",
" \"items\": {",
" \"type\": \"boolean\"",
" }",
"};",
"",
"var data1 = [true, false];",
"var data2 = [true, 123];",
"",
"pm.test('Schema is valid', function() {",
" pm.expect(tv4.validate(data1, schema)).to.be.true;",
"// pm.expect(tv4.validate(data2, schema)).to.be.true; // this statement would not be true",
"});",
""
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://postman-echo.com/get?foo1=bar1&foo2=bar2",
"protocol": "https",
"host": [
"postman-echo",
"com"
],
"path": [
"get"
],
"query": [
{
"key": "foo1",
"value": "bar1"
},
{
"key": "foo2",
"value": "bar2"
}
]
},
"description": "A schema is simply a declaration describing the structure of data. Some teams use a specific schema and would like to validate their server responses against this schema. You can define a custom schema, and validate your your server responses against this schema.\n\nOne of the API tests that we previously talked about is validating that the response payloads returned from the server are well-formed. You can do that by making assertions that elements in the response match your expectations. \n\nReview the test written under the **Tests** tab to validate that response payloads returned from the server are well-formed. \n\nThis example uses [Tiny Validator for JSON Schema v4](http://geraintluff.github.io/tv4/). The Postman sandbox offers a built-in tv4 validator to simplify your assertions. Use [json-schema](http://json-schema.org/) [draft v4](http://json-schema.org/latest/json-schema-core.html) to validate simple values and complex objects using a rich [validation vocabulary](http://json-schema.org/latest/json-schema-validation.html) ([examples](http://json-schema.org/examples.html)).\n\n"
},
"response": [
{
"name": "JSON schema v4",
"originalRequest": {
"method": "GET",
"header": [],
"url": {
"raw": "https://postman-echo.com/get?foo1=bar1&foo2=bar2",
"protocol": "https",
"host": [
"postman-echo",
"com"
],
"path": [
"get"
],
"query": [
{
"key": "foo1",
"value": "bar1"
},
{
"key": "foo2",
"value": "bar2"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Encoding",
"value": "gzip"
},
{
"key": "Content-Type",
"value": "application/json; charset=utf-8"
},
{
"key": "Date",
"value": "Thu, 15 Nov 2018 22:26:56 GMT"
},
{
"key": "ETag",
"value": "W/\"1c7-KZYP4szBTzxKQXHzZuUzeRc6eu8\""
},
{
"key": "Server",
"value": "nginx"
},
{
"key": "set-cookie",
"value": "sails.sid=s%3Azdvp_jvbvOB5mzzWKmS_7y6miNWal_a6.J5pGiESESIJ0CZLwvG9rF5Vsk4deBwxJhwo9E9JS4o8; Path=/; HttpOnly"
},
{
"key": "Vary",
"value": "Accept-Encoding"
},
{
"key": "Content-Length",
"value": "342"
},
{
"key": "Connection",
"value": "keep-alive"
}
],
"cookie": [],
"body": "{\n \"args\": {\n \"foo1\": \"bar1\",\n \"foo2\": \"bar2\"\n },\n \"headers\": {\n \"x-forwarded-proto\": \"https\",\n \"host\": \"postman-echo.com\",\n \"accept\": \"*/*\",\n \"accept-encoding\": \"gzip, deflate\",\n \"cache-control\": \"no-cache\",\n \"cookie\": \"sails.sid=s%3AwJjqwuZdKqKOiQ9FVnzMr8QoFaPFxpfD.ldt8sflpZLQkRbE1yyJtcIZIuirLfn4yFsVxtvFolWY\",\n \"postman-token\": \"9dd498fe-4233-4512-a506-974f85cab10d\",\n \"user-agent\": \"PostmanRuntime/7.3.0\",\n \"x-forwarded-port\": \"443\"\n },\n \"url\": \"https://postman-echo.com/get?foo1=bar1&foo2=bar2\"\n}"
}
]
}
],
"description": "This folder contains examples of testing a single HTTP API request.\n\nIn the Postman app, under the **Tests** tab of the request builder for each request, notice the test(s) written to validate specific assertions. Some of these tests are available as a SNIPPET on the right sidebar.\n\nSend each request to see the results under the **Tests** tab in the response viewer.",
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
]
}
],
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
]
}