1
00:00:00,000 --> 00:00:01,920
In this video we're going to talk about

2
00:00:01,920 --> 00:00:04,830
importing existing API definitions into

3
00:00:04,830 --> 00:00:07,620
Postman. So some APIs are set up with a

4
00:00:07,620 --> 00:00:09,719
schema that defines them. There's a few

5
00:00:09,719 --> 00:00:12,030
common formats for these schemas, and one

6
00:00:12,030 --> 00:00:14,210
of the most widely used is one called

7
00:00:14,210 --> 00:00:16,230
swagger. It's an open source

8
00:00:16,230 --> 00:00:17,550
specification and it's actually been

9
00:00:17,550 --> 00:00:19,949
recently renamed to open API, so you

10
00:00:19,949 --> 00:00:21,689
might hear either name, you might hear it

11
00:00:21,689 --> 00:00:23,730
talked to a swagger definitions or open

12
00:00:23,730 --> 00:00:25,980
API definitions. And essentially what

13
00:00:25,980 --> 00:00:27,990
this is is a structured way to define

14
00:00:27,990 --> 00:00:29,730
what your API does, so that both humans

15
00:00:29,730 --> 00:00:32,369
and computers can quickly and easily see

16
00:00:32,369 --> 00:00:34,020
what an API does and how it works.

17
00:00:34,020 --> 00:00:35,730
Postman supports the open API

18
00:00:35,730 --> 00:00:38,280
specification and you can easily import

19
00:00:38,280 --> 00:00:41,370
any open API definition into it. So let's

20
00:00:41,370 --> 00:00:43,230
maybe make this a little more real, let's

21
00:00:43,230 --> 00:00:45,930
take a look at an example open API spec

22
00:00:45,930 --> 00:00:48,030
file, see what it looks like. So I have

23
00:00:48,030 --> 00:00:50,850
here a file pet store demo, it's defined

24
00:00:50,850 --> 00:00:53,070
in the yamo format, it can also be

25
00:00:53,070 --> 00:00:54,690
defined as JSON but we'll look at a

26
00:00:54,690 --> 00:00:57,870
Yamma one here. And what this does is

27
00:00:57,870 --> 00:01:01,969
defines the structure and an schema of

28
00:01:01,969 --> 00:01:05,220
this API. So you can see here it's got

29
00:01:05,220 --> 00:01:06,840
the URL where it's supposed to come from,

30
00:01:06,840 --> 00:01:09,330
and then we have the paths. So the first

31
00:01:09,330 --> 00:01:11,490
path we have it's kind of an endpoint

32
00:01:11,490 --> 00:01:14,280
right slash pets, and under there we have

33
00:01:14,280 --> 00:01:16,530
a GET so we can GET on this pets

34
00:01:16,530 --> 00:01:19,619
endpoint, and we also have a POST so we

35
00:01:19,619 --> 00:01:21,840
can POST on the endpoint. So for the GET

36
00:01:21,840 --> 00:01:23,880
if we look at it, what it'll do is list

37
00:01:23,880 --> 00:01:26,100
pet, so it'll list all the pets in the

38
00:01:26,100 --> 00:01:28,320
system, and for POST what it will do is

39
00:01:28,320 --> 00:01:30,450
create a pet, so when we do a POST to

40
00:01:30,450 --> 00:01:32,939
this URL it'll create a new pet. There's

41
00:01:32,939 --> 00:01:34,409
also another endpoint called

42
00:01:34,409 --> 00:01:38,610
slash pet pet ID, and in this case we can

43
00:01:38,610 --> 00:01:39,960
get the information for one particular

44
00:01:39,960 --> 00:01:42,899
pet. So we can pass in the ID of a pet

45
00:01:42,899 --> 00:01:44,640
that we're interested in and we can use

46
00:01:44,640 --> 00:01:46,740
the GET on this to get information about

47
00:01:46,740 --> 00:01:48,720
that pet. And if we call it close that

48
00:01:48,720 --> 00:01:49,950
there's nothing else, so there's

49
00:01:49,950 --> 00:01:52,619
basically these two paths and this one

50
00:01:52,619 --> 00:01:54,509
has to GET in a POST and this one just

51
00:01:54,509 --> 00:01:56,130
says a GET. So this is a very small

52
00:01:56,130 --> 00:01:58,469
simple API that we've defined here in

53
00:01:58,469 --> 00:02:00,869
this file. And then there's also the

54
00:02:00,869 --> 00:02:03,259
schema, so the schema defines what is

55
00:02:03,259 --> 00:02:06,570
allowed on these various paths. So the

56
00:02:06,570 --> 00:02:09,660
pet path requires an ID and a name, and

57
00:02:09,660 --> 00:02:12,150
then down here shows what those need to

58
00:02:12,150 --> 00:02:13,919
be, so the ID needs to be an integer

59
00:02:13,919 --> 00:02:15,569
the name needs to be a string, and then

60
00:02:15,569 --> 00:02:17,850
there's this other optional parameter as

61
00:02:17,850 --> 00:02:20,310
well or property which is tagged and

62
00:02:20,310 --> 00:02:23,220
that needs to be a string as well. So

63
00:02:23,220 --> 00:02:24,780
that kind of is what an open API

64
00:02:24,780 --> 00:02:27,240
specification looks like, that's how it

65
00:02:27,240 --> 00:02:29,610
sets things up and specifies things, and

66
00:02:29,610 --> 00:02:31,050
it puts it in the structured format so

67
00:02:31,050 --> 00:02:32,520
that we can read that as humans and

68
00:02:32,520 --> 00:02:35,790
understand it. But also a computer can

69
00:02:35,790 --> 00:02:37,709
very easily understand this as well. So

70
00:02:37,709 --> 00:02:40,110
if we go over to Postman we can import

71
00:02:40,110 --> 00:02:41,730
that file that we were just looking at.

72
00:02:41,730 --> 00:02:47,430
So let's go find it, so an API will use

73
00:02:47,430 --> 00:02:49,950
this pet store yamo file that we were

74
00:02:49,950 --> 00:02:52,320
looking at, we'll open that and you can

75
00:02:52,320 --> 00:02:54,480
see it says it's imported. And if we look

76
00:02:54,480 --> 00:02:56,489
over here we've got the swagger spec pet

77
00:02:56,489 --> 00:02:58,850
store collection that's been added, and

78
00:02:58,850 --> 00:03:03,300
under here we have pets, so GET to list

79
00:03:03,300 --> 00:03:08,280
all pets, we have POST which is posts to

80
00:03:08,280 --> 00:03:11,519
the pets URL, and then we have GET on the

81
00:03:11,519 --> 00:03:14,100
pet ID as well. So you can see that just

82
00:03:14,100 --> 00:03:16,650
with one import of that file, Postman is

83
00:03:16,650 --> 00:03:19,440
able to infer the entire API structure

84
00:03:19,440 --> 00:03:21,150
from that because it's in this defined

85
00:03:21,150 --> 00:03:23,250
format. So you can see that this would be

86
00:03:23,250 --> 00:03:25,200
very useful figuring out what options to

87
00:03:25,200 --> 00:03:27,870
test on an API, and it can also be used

88
00:03:27,870 --> 00:03:29,820
to easily bring API definitions into

89
00:03:29,820 --> 00:03:32,400
Postman, so that we can set it up and

90
00:03:32,400 --> 00:03:34,079
have all the structure in place that we

91
00:03:34,079 --> 00:03:37,590
want. So not all APIs provide files like

92
00:03:37,590 --> 00:03:39,239
this, but if they do this is a very

93
00:03:39,239 --> 00:03:41,160
useful testing tool to get the coverage

94
00:03:41,160 --> 00:03:44,040
that you want on an API. In the next

95
00:03:44,040 --> 00:03:45,420
video we'll be looking at how we can

96
00:03:45,420 --> 00:03:47,760
validate API schemas using something

97
00:03:47,760 --> 00:03:52,760
called tv4, hope to see you there.
