1 00:00:00,820 --> 00:00:05,010 In class video we realize that we're going to have to start working on this API server before we can 2 00:00:05,010 --> 00:00:09,120 really progress forward much further with the form that we are currently working on. 3 00:00:09,120 --> 00:00:12,360 So in this video we're going to start to learn a little bit about how we're going to put together this 4 00:00:12,360 --> 00:00:13,380 API server. 5 00:00:13,560 --> 00:00:18,090 Now remember at the end the last video I had told you that this was going to be pretty easy and straightforward 6 00:00:18,270 --> 00:00:23,530 for the app guys server and it's because we're going to use a little package to help us put it together. 7 00:00:23,610 --> 00:00:28,370 So I'm going to pull open some documentation for a package called Jaison server. 8 00:00:28,550 --> 00:00:30,320 I'm going to copy this link right here. 9 00:00:30,330 --> 00:00:33,350 Open up a new tab and navigate to it. 10 00:00:33,360 --> 00:00:36,030 All right so here's the documentation for JS on server. 11 00:00:36,330 --> 00:00:40,160 When you look at this documentation some of it might seem a little bit familiar. 12 00:00:40,380 --> 00:00:46,050 It might look familiar because this package is what is powering that same API we used earlier on in 13 00:00:46,050 --> 00:00:46,830 the course. 14 00:00:46,830 --> 00:00:52,290 If you remember that Type-I code Jaison placeholder this thing right here. 15 00:00:52,290 --> 00:00:57,660 So we use this and point earlier in the courts this end point this server is using the base on server 16 00:00:57,690 --> 00:00:58,620 package. 17 00:00:58,680 --> 00:01:01,760 So you're kind of already familiar with using this thing. 18 00:01:01,770 --> 00:01:06,570 Now the reason that we are going to use JS on server in particular as opposed to putting something together 19 00:01:06,570 --> 00:01:13,230 from scratch with say Express or something like that is that JS on server has a extremely strict adherence 20 00:01:13,410 --> 00:01:16,110 to something called restful conventions. 21 00:01:16,110 --> 00:01:19,010 Let me tell you a little bit more about what restful conventions are. 22 00:01:21,790 --> 00:01:27,550 Arrest conventions or restful conventions are a predefined system for defining different routes on an 23 00:01:27,550 --> 00:01:32,150 API that work with a given type of records. 24 00:01:32,270 --> 00:01:33,310 That's super unclear. 25 00:01:33,320 --> 00:01:37,110 Even when I say it so let me show you a diagram that's going to explain what this really is. 26 00:01:37,250 --> 00:01:42,380 I want you to think about the different streams that we are trying to create and show and delete and 27 00:01:42,410 --> 00:01:44,330 update inside of our applications. 28 00:01:44,340 --> 00:01:48,130 There's really a set number of ways that you and I are going to work with these streams. 29 00:01:48,140 --> 00:01:51,290 We kind of already discussed this when we were talking about the different components that we are going 30 00:01:51,290 --> 00:01:52,520 to create. 31 00:01:52,730 --> 00:01:56,860 We probably want to have the ability to list all the different streams that have been created inside 32 00:01:56,860 --> 00:01:58,080 of application. 33 00:01:58,100 --> 00:02:03,940 We probably want to have the ability to get details about one stream we probably want to create a stream. 34 00:02:04,010 --> 00:02:08,930 We probably want to be able to update a stream and delete a stream so these actions right here are these 35 00:02:08,930 --> 00:02:14,060 different ways of manipulating a record are all probably the most common ways that we are going to want 36 00:02:14,060 --> 00:02:18,020 to interact with these stream objects that we are trying to create. 37 00:02:18,020 --> 00:02:24,650 So the term restful conventions is essentially referring to a standardized system of routes and request 38 00:02:24,650 --> 00:02:29,340 methods used to commit or operate all these different actions. 39 00:02:29,630 --> 00:02:35,780 So following restful conventions if we want to list all records released all the streams that are stored 40 00:02:35,810 --> 00:02:43,850 on our API server then by convention we will make a get request to a get type HTP request to the route 41 00:02:43,940 --> 00:02:46,420 streams on our API server. 42 00:02:46,880 --> 00:02:52,970 If our API server follows restful conventions then whenever we make a request to slash streams the API 43 00:02:52,970 --> 00:02:57,760 server should return an array of all the different stream objects that it holds. 44 00:02:57,770 --> 00:03:02,920 Now the API server doesn't have to the API server could define this stream's route. 45 00:03:02,930 --> 00:03:05,780 Where they get request as like for some crazy reason. 46 00:03:05,780 --> 00:03:07,310 Deleting all streams. 47 00:03:07,400 --> 00:03:08,210 That's totally possible. 48 00:03:08,210 --> 00:03:14,270 We don't have to define define a API server to behave in any which way we can have it behave in any 49 00:03:14,270 --> 00:03:15,260 way we want. 50 00:03:15,500 --> 00:03:21,020 But in order to make our API is easier to work with for like other engineers we usually try to follow 51 00:03:21,080 --> 00:03:22,610 these restful conventions. 52 00:03:22,610 --> 00:03:24,410 So this is not a hard requirement. 53 00:03:24,410 --> 00:03:25,920 It is highly recommended. 54 00:03:25,940 --> 00:03:31,040 Just to make it easier for other engineers to work with software that you design. 55 00:03:31,050 --> 00:03:36,150 So if we want to list all records we will make a get request to slash streams if we want to get one 56 00:03:36,150 --> 00:03:36,920 particular record. 57 00:03:36,930 --> 00:03:42,420 We'll make a get request to streams slash and then the idea of the stream that we want to retrieve to 58 00:03:42,420 --> 00:03:46,630 create a stream will make a post request request to slash streams. 59 00:03:46,760 --> 00:03:52,260 And if we update a record we'll make a put two streams slash and then the ID and same thing for delete 60 00:03:52,290 --> 00:03:55,200 as well but delete method instead. 61 00:03:55,200 --> 00:04:00,870 So again the reason that we are making use of JS on server is that it very strictly adhered to all these 62 00:04:00,870 --> 00:04:02,140 restful conventions. 63 00:04:02,370 --> 00:04:07,540 If you want to get a list of all the different streams stored by JS on server we are going to make a 64 00:04:07,710 --> 00:04:14,040 request to slash streams and then Jay Sun server it will return a list of any streams that exist inside 65 00:04:14,040 --> 00:04:15,510 the application. 66 00:04:15,510 --> 00:04:19,740 So again the reason we're making these suggestions here as opposed to using something like Express is 67 00:04:19,740 --> 00:04:24,920 just to make sure that you really understand these basic conventions in a re-act application. 68 00:04:24,930 --> 00:04:30,330 And there's no possibility of us wiring up a Express server or something like that in some funky way 69 00:04:30,330 --> 00:04:33,150 that doesn't obey restful conventions. 70 00:04:33,150 --> 00:04:34,950 All right so that's the idea. 71 00:04:34,980 --> 00:04:36,350 So let's take a pause right here. 72 00:04:36,360 --> 00:04:40,500 When we come back the next section we're going to start to set up use on server side of our project 73 00:04:40,670 --> 00:04:44,580 and we'll start to make a couple of test requests over to it just to make sure that it works the way 74 00:04:44,580 --> 00:04:45,350 we expect. 75 00:04:45,510 --> 00:04:47,730 So quick Pozen I'll see you in just a minute.