WEBVTT 0 00:00.240 --> 00:07.290 Hey guys. In this module we're going to be talking all about APIs, Application Programming Interfaces. 1 00:07.350 --> 00:13.830 Now it's very likely, if you spend any time on the Internet at all, you would have heard of this term 2 00:14.010 --> 00:16.170 crop up every so often. 3 00:16.170 --> 00:22.500 So in the coming lessons of this module, we're going to explore what exactly APIs are, and what we can 4 00:22.500 --> 00:23.980 do with it. 5 00:24.000 --> 00:30.000 First things first. In this module you're going to be exploring a number of APIs, and you're going to 6 00:30.000 --> 00:36.490 be building a weather application, as well as a email sign up web application. 7 00:36.510 --> 00:43.470 This is going to allow you to collect real users’ email addresses, and save it to your own database on MailChimp, 8 00:43.920 --> 00:46.170 so that you can contact them at a later point. 9 00:46.170 --> 00:52.980 And this is really useful if you decide to create a landing page and email people when your product 10 00:52.980 --> 00:59.260 launches, or if you're trying to set up an email newsletter and stay in touch with your subscribers. 11 00:59.340 --> 01:00.890 So that's the goal. 12 01:00.930 --> 01:08.430 Now, in order to get there though, we first have to understand what are APIs, and why are they useful. 13 01:08.430 --> 01:16.560 Now, if you went onto yahoo.com, and you took a look at their little weather section on the right, you'll 14 01:16.560 --> 01:23.700 notice that it takes the current location of your web browser, and gives you the upcoming weather forecast 15 01:23.760 --> 01:25.680 for your location. 16 01:25.680 --> 01:32.310 Now, if we wanted to create our own web site, and we wanted a little module like this, how would we do 17 01:32.310 --> 01:32.920 that? 18 01:33.060 --> 01:36.270 Because we're not going to go around collecting weather data, right? 19 01:36.300 --> 01:43.470 We're not really kitted out to be able to detect wind speed and the temperature and forecast what 20 01:43.470 --> 01:45.950 the weather will be like in the future. 21 01:45.990 --> 01:48.590 So where do we get this data anyways? 22 01:48.630 --> 01:56.880 Well, we could use a weather data service, like OpenWeatherMap, where their job is to collect these pieces 23 01:56.880 --> 02:02.900 of data and organize it and do all of the complicated things to forecast the weather, 24 02:03.450 --> 02:10.560 and then all we have to do is to use their API to tap into that live weather data, and we'll be able to 25 02:10.560 --> 02:12.390 start pulling it into our web site, 26 02:12.510 --> 02:15.300 just like how Yahoo does it here. 27 02:16.020 --> 02:22.410 Now similarly, when you go onto Tinder, and you've seen that section where it says ‘Shared Friends’ or 28 02:22.410 --> 02:24.210 ‘Shared Interests’, 29 02:24.210 --> 02:27.090 where did these pieces of data come from? 30 02:27.090 --> 02:30.590 Well, it comes from when the user logs in with Facebook. 31 02:30.720 --> 02:38.280 Tinder is able to ask Facebook for these pieces of data on the user, and then it can use that data to 32 02:38.280 --> 02:44.790 populate these sections, and it will do that through the use of the Facebook API in order to get that 33 02:44.790 --> 02:46.470 data from Facebook. 34 02:46.470 --> 02:51.090 Now out there there are loads of different types of APIs that you can use. 35 02:51.180 --> 02:58.590 For example, in the UK we have the Police API, which gives us granular data on where certain crimes have 36 02:58.590 --> 03:04.830 happened, on things like what happened with that crime, who was involved, and a whole lot of things. 37 03:04.860 --> 03:12.100 And through the use of an API like this, people are able to build interesting web sites, like this one. 38 03:12.360 --> 03:14.130 This is called Murder Map. 39 03:14.130 --> 03:21.000 It has a little bit of a dark name, and it's a little bit of a strange web site, but it takes that data 40 03:21.000 --> 03:29.520 from the police API, and it maps out all of the murders that take place in London by location as well 41 03:29.520 --> 03:35.700 as by weapon, by date, and by the age and gender of the victim. 42 03:35.790 --> 03:41.040 And it's really interesting to see this data mapped out, especially if you're trying to figure out where 43 03:41.040 --> 03:41.880 you want to live. 44 03:42.540 --> 03:49.500 So maybe stay away from gun and knife crime, but maybe poisoning and other things won't affect you so 45 03:49.500 --> 03:50.390 much. 46 03:50.580 --> 03:55.400 So in the coming lessons, I'm going to be introducing you to some really fun API. 47 03:55.620 --> 04:02.460 But there's all sorts of APIs out there, and they range from things such as APIs that give you data 48 04:02.490 --> 04:09.580 on the prices of various stocks, to things like an API that gives you data on various Pokémon, 49 04:09.600 --> 04:13.480 so all the way from very serious to very not serious. 50 04:13.530 --> 04:21.460 You can access all sorts of data via APIs and use them to create your own web sites. 51 04:21.460 --> 04:24.000 Now we've talked so much about APIs. 52 04:24.060 --> 04:27.310 What exactly is the definition of an API? 53 04:27.420 --> 04:34.110 A broad definition that a lot of people go by is that an API is a set of commands, functions, protocols 54 04:34.110 --> 04:41.730 and objects that programmers can use to create software or interact with an external system. 55 04:41.760 --> 04:43.770 So what does all of that mean? 56 04:43.770 --> 04:45.220 Well, let's simplify it. 57 04:45.420 --> 04:51.750 Let's say that you were going to a restaurant, and in a restaurant we know that there are the things 58 04:51.750 --> 04:58.590 that are on the menu, say various cakes and desserts that they sell, but you could also go into the kitchen 59 04:58.590 --> 05:05.590 and you would find there’s loads of raw ingredients, and probably a couple of surprised chefs as to what it 60 05:05.590 --> 05:07.490 is you're doing in the kitchen. 61 05:07.840 --> 05:13.360 Now if you had just decided that you were going to go into the kitchen pantry and just start eating 62 05:13.360 --> 05:17.410 things that they have they're, like just start spooning some mayonnaise, 63 05:17.410 --> 05:23.050 then the restaurant's going to be pretty shocked, right, and they're going to be pretty unhappy about that, 64 05:23.590 --> 05:28.120 because there are certain things which they sell and they will let you buy, 65 05:28.150 --> 05:31.730 but then there's other things which are kind of off limits. 66 05:31.870 --> 05:38.530 It's kind of similar with data. For every web site that has their own data, be it Facebook, which has data 67 05:38.560 --> 05:44.170 on their users, or something like the police API, which has data on crimes, 68 05:44.320 --> 05:48.490 there’s certain pieces of data that they will allow you to access, 69 05:49.000 --> 05:53.850 but there's other pieces of data that's not really your business. 70 05:54.670 --> 06:00.730 So how can these web sites tell you what are the things that you can actually access from them and how 71 06:00.730 --> 06:02.010 to do that? 72 06:02.020 --> 06:08.130 Well, if we were in a restaurant then they might provide that information in the form of a menu, 73 06:08.290 --> 06:08.590 right? 74 06:08.590 --> 06:14.980 So at this restaurant you can buy cakes, you can buy sandwiches, tea and coffee. And for a service like 75 06:15.040 --> 06:22.030 a weather API, say like OpenWeatherMap, then the kind of data that you can access include things like 76 06:22.030 --> 06:29.110 the temperature, the weather conditions, the weather images, and maybe the atmospheric pressure. In API, 77 06:29.110 --> 06:38.210 some people will consider to be a contract. It’s a contract between the data provider and the developer. 78 06:38.260 --> 06:46.150 And essentially what it says is these are all the things that developers can access, and these are the 79 06:46.150 --> 06:51.520 methods, the objects, the protocols that you would use to access them. 80 06:51.520 --> 06:59.860 And we, as the web site that hosts the data, will try to not change any of these methods or functions without 81 06:59.860 --> 07:01.170 notifying you. 82 07:01.600 --> 07:07.450 Coming back to our definition, then it starts to make a little bit more sense, right, where an API is a 83 07:07.450 --> 07:14.740 set of commands, functions, protocols and objects that programmers can use to create software or interact 84 07:14.860 --> 07:17.050 with an external system. 85 07:17.050 --> 07:24.700 Now we've seen a lot of examples of an API that allows you to interact with an external system, but we 86 07:24.700 --> 07:29.640 haven't really seen any that allow you to create software, or have we? 87 07:29.660 --> 07:32.250 Well, if you think about it, when we learnt about 88 07:32.260 --> 07:33.640 jQuery, what is 89 07:33.640 --> 07:37.060 jQuery? Well, it's an API, right? 90 07:37.090 --> 07:43.090 It's something that gives you access to a whole bunch of functions and objects that let you create software 91 07:43.330 --> 07:47.680 much more easily than if you were just writing vanilla Javascript. 92 07:47.680 --> 07:54.370 Now if we think back to the Tinder example, where Tinder was getting data from Facebook to get the shared 93 07:54.370 --> 07:57.030 friends and shared interests of their users, 94 07:57.040 --> 08:03.400 well this is a case where they're using the Facebook API to interact with an external system, namely 95 08:03.550 --> 08:05.800 the Facebook database. 96 08:05.800 --> 08:13.390 Now in this module we're going to focus on the types of APIs that allow us to interact with an external 97 08:13.390 --> 08:14.240 system, 98 08:14.440 --> 08:18.000 and most importantly an external server. 99 08:18.040 --> 08:22.920 So we're going to get hold of some piece of data from a web site, 100 08:23.110 --> 08:30.050 and we're going to do that through their API, and we're going to read their documentation to see what are 101 08:30.070 --> 08:31.770 all the things that we can do. 102 08:31.840 --> 08:40.330 And we're going to use their API as a menu of things that we can do to interact with their data. 103 08:40.330 --> 08:42.880 So that's a little bit on the theory of API, 104 08:43.360 --> 08:49.300 but in the next lesson we're going to look at how we can put it into practice. For all of that and more, 105 08:49.510 --> 08:50.080 I'll see you there.