1 00:00:00,190 --> 00:00:04,830 To get a sense of what the rest API is let's first talk about rest. 2 00:00:04,830 --> 00:00:08,510 Rest stands for representational state transfer and 3 00:00:08,510 --> 00:00:13,710 is a way of defining how a web server should respond to requests. 4 00:00:13,710 --> 00:00:17,510 Normally when humans interact with the Internet they use a web browser 5 00:00:17,510 --> 00:00:18,950 as a client. 6 00:00:18,950 --> 00:00:23,940 The browser makes a request to the server and HTML and CSS is returned. 7 00:00:23,940 --> 00:00:25,350 It's human friendly. 8 00:00:25,350 --> 00:00:30,210 Machines can also make requests to URLs and ask for resources. 9 00:00:30,210 --> 00:00:33,930 These responses are intended for machines, not humans, so 10 00:00:33,930 --> 00:00:37,610 no HTML and CSS are returned. 11 00:00:37,610 --> 00:00:41,100 This type of response is normally formatted in JSON. 12 00:00:41,100 --> 00:00:44,620 A good example of this is the Twitter app on your phone, 13 00:00:44,620 --> 00:00:49,710 it makes a request to Twitter's rest API to get the tweets before you see them. 14 00:00:49,710 --> 00:00:53,750 The JSON from Twitter's API is then formatted and displayed on your phone. 15 00:00:53,750 --> 00:01:00,460 API is done only allow you to read data but also add update and delete data. 16 00:01:00,460 --> 00:01:05,940 Each of these actions can be mapped to an HTTP verb post, put or delete. 17 00:01:05,940 --> 00:01:11,540 By combining an HTTP verb with a URL an API can do many things. 18 00:01:11,540 --> 00:01:15,030 Such as post tweets, delete emails or even transfer money. 19 00:01:16,100 --> 00:01:20,490 When a set of URLs are designed to interface with a back end program in this 20 00:01:20,490 --> 00:01:25,610 way we call it a Rest API, or application programming interface. 21 00:01:26,650 --> 00:01:30,440 Let's look at the demo user interface for our Rest API again. 22 00:01:30,440 --> 00:01:34,380 I'll open up the Chrome developer tools and then click on the network tab. 23 00:01:36,492 --> 00:01:40,390 This will allow us to see what's happening when we use our user interface. 24 00:01:42,090 --> 00:01:46,430 When we submitted new question like why is the sky 25 00:01:49,520 --> 00:01:55,139 blue, our UI makes an http post request to the URL slash questions. 26 00:01:58,570 --> 00:02:00,260 This is via an AJAX call. 27 00:02:01,990 --> 00:02:05,806 The server responds by inserting a new question into the database and 28 00:02:05,806 --> 00:02:08,125 returning it back so it can be displayed. 29 00:02:14,431 --> 00:02:15,903 When we brought an answer up 30 00:02:21,975 --> 00:02:25,374 The UI posts a request to the URL pattern. 31 00:02:25,374 --> 00:02:29,840 Questions, question ID, answers, answer ID, vote-up. 32 00:02:29,840 --> 00:02:35,944 The seven responds by increment in the specified and says vote counts and 33 00:02:35,944 --> 00:02:41,360 returning the whole question back with it's answers. 34 00:02:41,360 --> 00:02:43,850 The UI can now be updated. 35 00:02:43,850 --> 00:02:46,970 Now that we have a sense of what a Rest API is and 36 00:02:46,970 --> 00:02:50,530 how it works, let's plan the API we want to build the next.