1
00:00:00,448 --> 00:00:01,925
- [Instructor] Hi and
welcome back to the course.

2
00:00:01,925 --> 00:00:03,283
In this video we're going to be testing

3
00:00:03,283 --> 00:00:04,622
everything with Postman

4
00:00:04,622 --> 00:00:07,692
and finalising our last
few endpoints in Postman

5
00:00:07,692 --> 00:00:08,848
as well as talking about

6
00:00:08,848 --> 00:00:11,699
how the database is
working in the background.

7
00:00:11,699 --> 00:00:13,299
This first thing I'm going
to do is I'm going to

8
00:00:13,299 --> 00:00:15,284
remove the data.db file

9
00:00:15,284 --> 00:00:19,011
and then I'm going to start the app

10
00:00:19,011 --> 00:00:21,511
and then go over into Postman.

11
00:00:22,403 --> 00:00:26,409
Now, I've got here the
collection in section six

12
00:00:26,409 --> 00:00:28,044
and as you can see this
collection contains

13
00:00:28,044 --> 00:00:30,292
nothing related to stores.

14
00:00:30,292 --> 00:00:32,412
So we're going to first
test these endpoints here

15
00:00:32,412 --> 00:00:35,179
and then we're going
to create some stores.

16
00:00:35,179 --> 00:00:37,014
Let's first register,

17
00:00:37,014 --> 00:00:38,684
which seems to work.

18
00:00:38,684 --> 00:00:41,037
Authenticate, which seems to work.

19
00:00:41,037 --> 00:00:44,886
Retrieve items, which seems to work.

20
00:00:44,886 --> 00:00:47,377
And now we're going to create an item.

21
00:00:47,377 --> 00:00:48,860
What do you think is going to happen

22
00:00:48,860 --> 00:00:50,777
when I press send?

23
00:00:54,702 --> 00:00:57,578
Well exactly what you'd expect I hope.

24
00:00:57,578 --> 00:00:59,889
It tells us that every
item needs a store ID,

25
00:00:59,889 --> 00:01:02,008
because we didn't include one.

26
00:01:02,008 --> 00:01:03,758
So let's include one.

27
00:01:05,847 --> 00:01:10,014
What do you think is going to
happen now when I press send?

28
00:01:13,520 --> 00:01:15,419
The result might surprise you.

29
00:01:15,419 --> 00:01:17,597
It just works

30
00:01:17,597 --> 00:01:21,430
even though we don't
have a store with ID one.

31
00:01:22,518 --> 00:01:26,291
Okay, now let's retrieve the test here,

32
00:01:26,291 --> 00:01:27,709
and that seems to work.

33
00:01:27,709 --> 00:01:30,292
We can even delete it

34
00:01:31,425 --> 00:01:34,852
and we can put it in again.

35
00:01:34,852 --> 00:01:36,935
Again we need a store ID,

36
00:01:38,939 --> 00:01:42,920
and we can put two and that seems to work.

37
00:01:42,920 --> 00:01:44,727
So the reason why it works is because

38
00:01:44,727 --> 00:01:46,780
SQLite doesn't have the concept

39
00:01:46,780 --> 00:01:50,038
of enforcing foreign key
relationships like that.

40
00:01:50,038 --> 00:01:53,788
MySQL and PostgreSQL
and other heavy duty SQL

41
00:01:54,790 --> 00:01:57,854
well relational database
management systems

42
00:01:57,854 --> 00:01:59,588
do have that so

43
00:01:59,588 --> 00:02:01,290
you wouldn't be able to make this work

44
00:02:01,290 --> 00:02:03,429
without creating the store first.

45
00:02:03,429 --> 00:02:04,944
SQLite doesn't have that,

46
00:02:04,944 --> 00:02:07,521
which allows us to test
our API quite nicely,

47
00:02:07,521 --> 00:02:10,076
but of course isn't really realistic,

48
00:02:10,076 --> 00:02:12,754
because now that we have an item

49
00:02:12,754 --> 00:02:14,798
with store ID two

50
00:02:14,798 --> 00:02:17,208
we can go and create two stores

51
00:02:17,208 --> 00:02:19,470
and the second one will have this item

52
00:02:19,470 --> 00:02:22,510
which is rather strange,

53
00:02:22,510 --> 00:02:23,952
but let's try it, nevertheless.

54
00:02:23,952 --> 00:02:26,259
The first thing that we're
going to do is duplicate

55
00:02:26,259 --> 00:02:29,057
the items name endpoint

56
00:02:29,057 --> 00:02:30,659
and we're going to

57
00:02:30,659 --> 00:02:34,826
call it store name

58
00:02:38,714 --> 00:02:40,740
and we're going to tweak the description

59
00:02:40,740 --> 00:02:43,927
to make sure that it is correct

60
00:02:43,927 --> 00:02:46,614
and then we're going to change it

61
00:02:46,614 --> 00:02:51,240
to make sure that it says
/store/ the store name.

62
00:02:51,240 --> 00:02:53,937
As you can see it says store not found,

63
00:02:53,937 --> 00:02:57,191
and even if we use test, which
we have an item called test

64
00:02:57,191 --> 00:02:59,286
it still says store not
found, because it's looking

65
00:02:59,286 --> 00:03:03,615
on the stores table as
opposed to the items table.

66
00:03:03,615 --> 00:03:06,915
Okay, now let's duplicate that

67
00:03:06,915 --> 00:03:10,582
and edit it and change it to a post

68
00:03:11,935 --> 00:03:13,685
and then edit it

69
00:03:17,532 --> 00:03:19,394
and change the description

70
00:03:19,394 --> 00:03:21,997
and now we can create this store there.

71
00:03:21,997 --> 00:03:24,426
And as you can see it has no items.

72
00:03:24,426 --> 00:03:27,739
If we create test two,
which is the second store

73
00:03:27,739 --> 00:03:30,500
this will have ID equal to two,

74
00:03:30,500 --> 00:03:32,583
and look at what happens.

75
00:03:33,543 --> 00:03:36,965
Ta-da, it gets created
with items inside it,

76
00:03:36,965 --> 00:03:39,145
because the items were
already in the database.

77
00:03:39,145 --> 00:03:41,518
Now that's fairly interesting,

78
00:03:41,518 --> 00:03:44,511
but it's probably not really a good thing.

79
00:03:44,511 --> 00:03:47,094
So SQLite has many limitations,

80
00:03:48,120 --> 00:03:48,953
this is one of them

81
00:03:48,953 --> 00:03:52,461
and another one is that it cannot write

82
00:03:52,461 --> 00:03:55,378
two things simultaneously in
the database, for example.

83
00:03:55,378 --> 00:03:57,900
So it's very limited compared
to professional systems,

84
00:03:57,900 --> 00:03:59,733
but it's quite useful.

85
00:04:00,574 --> 00:04:03,261
Finally let's look at deleting

86
00:04:03,261 --> 00:04:05,402
and we're going to change that to delete.

87
00:04:05,402 --> 00:04:08,502
We can send it, and
this says store deleted.

88
00:04:08,502 --> 00:04:10,669
Remember also to edit this

89
00:04:11,710 --> 00:04:14,703
to make sure it is accurate.

90
00:04:14,703 --> 00:04:17,603
And finally the last one is going to be

91
00:04:17,603 --> 00:04:21,186
the get a list of stores.

92
00:04:31,373 --> 00:04:35,090
Remember to change everything to stores

93
00:04:35,090 --> 00:04:38,486
where appropriate, which I didn't do

94
00:04:38,486 --> 00:04:39,897
so I'm going to click this one,

95
00:04:39,897 --> 00:04:42,713
change it to stores and save it.

96
00:04:42,713 --> 00:04:44,101
And as you can see we get

97
00:04:44,101 --> 00:04:46,308
the stored that we didn't delete.

98
00:04:46,308 --> 00:04:48,725
We can go ahead and delete it

99
00:04:49,731 --> 00:04:51,359
and then retrieve the stores again

100
00:04:51,359 --> 00:04:54,027
and the stores is empty.

101
00:04:54,027 --> 00:04:56,742
So hopefully throughout this you have

102
00:04:56,742 --> 00:04:59,969
seen how easy it can be once you've got

103
00:04:59,969 --> 00:05:02,134
some knowledge to create

104
00:05:02,134 --> 00:05:04,508
a rest API that has relationships

105
00:05:04,508 --> 00:05:07,957
and that allows your mobile
and web applications to easily

106
00:05:07,957 --> 00:05:11,445
insert and retrieve and update data,

107
00:05:11,445 --> 00:05:13,736
which is normally

108
00:05:13,736 --> 00:05:15,774
what a rest API could be used for.

109
00:05:15,774 --> 00:05:18,063
Now it can also be used
for many other things

110
00:05:18,063 --> 00:05:23,045
that we could look into,
such as sending emails or

111
00:05:23,045 --> 00:05:27,449
holding user data, processing
payments, etcetera.

112
00:05:27,449 --> 00:05:28,616
Now many of those things are out

113
00:05:28,616 --> 00:05:30,376
with the scope of this course,

114
00:05:30,376 --> 00:05:32,255
because I wanted to teach you about

115
00:05:32,255 --> 00:05:35,087
authentication, SQLAlchemy,

116
00:05:35,087 --> 00:05:36,861
as well as Flask-RESTful,

117
00:05:36,861 --> 00:05:38,737
but there are many other
things that are not

118
00:05:38,737 --> 00:05:40,188
out with the scope of this course,

119
00:05:40,188 --> 00:05:43,450
such as deployments, which we will look at

120
00:05:43,450 --> 00:05:45,417
shortly in this course.

121
00:05:45,417 --> 00:05:47,774
In addition at the end of
the course we'll also build

122
00:05:47,774 --> 00:05:50,042
a larger more complex project

123
00:05:50,042 --> 00:05:52,348
so stay tuned for that as well,

124
00:05:52,348 --> 00:05:53,755
but that's it for this section.

125
00:05:53,755 --> 00:05:56,191
Hopefully you've enjoyed
building this project with me

126
00:05:56,191 --> 00:05:59,108
and I'll see you in the next video.

