1 00:00:00,260 --> 00:00:02,460 Welcome to this video using parameters 2 00:00:02,460 --> 00:00:05,069 and API calls. Up until now we've talked 3 00:00:05,069 --> 00:00:07,529 about endpoints using GET calls, but in 4 00:00:07,529 --> 00:00:08,849 this video we're going to dive a bit 5 00:00:08,849 --> 00:00:11,070 deeper and look at how to use parameters 6 00:00:11,070 --> 00:00:13,099 inside of API calls. 7 00:00:13,099 --> 00:00:15,509 So Postman gives you a couple of ways of 8 00:00:15,509 --> 00:00:17,460 doing this, but let's kind of dive in and 9 00:00:17,460 --> 00:00:18,960 look at a real life example. So we'll 10 00:00:18,960 --> 00:00:21,300 pull up the documentation here for the 11 00:00:21,300 --> 00:00:23,730 SpaceX API. And you can see there's a 12 00:00:23,730 --> 00:00:25,949 number of different endpoints that are 13 00:00:25,949 --> 00:00:28,320 available to us here on the left. Well 14 00:00:28,320 --> 00:00:29,910 the one we'll take a look at is the 15 00:00:29,910 --> 00:00:33,210 launches API. So this is an endpoint that 16 00:00:33,210 --> 00:00:34,829 gives us information about the different 17 00:00:34,829 --> 00:00:37,469 launches that SpaceX has had, and is 18 00:00:37,469 --> 00:00:39,570 planning in the future. So I've already 19 00:00:39,570 --> 00:00:42,660 got this open for us in Postman here, you 20 00:00:42,660 --> 00:00:45,420 can see I've got the URL in here, it's a 21 00:00:45,420 --> 00:00:47,399 GET request and down here we can see 22 00:00:47,399 --> 00:00:50,010 that it gives us back quite a big list 23 00:00:50,010 --> 00:00:53,699 of information about the various 24 00:00:53,699 --> 00:00:57,180 launches that SpaceX has done over the 25 00:00:57,180 --> 00:01:00,000 years. So this gives us a big long list 26 00:01:00,000 --> 00:01:02,719 of all the launches that have been done. 27 00:01:02,719 --> 00:01:05,400 Now if we go back to the documentation, 28 00:01:05,400 --> 00:01:07,619 we can see down here that it has a 29 00:01:07,619 --> 00:01:09,930 number of optional query strings, and 30 00:01:09,930 --> 00:01:11,850 then down here as well it has a number 31 00:01:11,850 --> 00:01:14,990 of optional output control query strings. 32 00:01:14,990 --> 00:01:18,450 So these are what we can call parameters, 33 00:01:18,450 --> 00:01:21,119 query strings is a kind of parameter. So 34 00:01:21,119 --> 00:01:22,710 you can see here's the parameter flight 35 00:01:22,710 --> 00:01:24,960 ID, and then there's a sample of what it 36 00:01:24,960 --> 00:01:27,180 might look like. And a number of 37 00:01:27,180 --> 00:01:28,799 different parameters here. So let's take 38 00:01:28,799 --> 00:01:30,860 some simple ones, let's look at limit and 39 00:01:30,860 --> 00:01:33,119 we'll put that in. So we'll go over to 40 00:01:33,119 --> 00:01:36,600 Postman, and Postman has this params tab 41 00:01:36,600 --> 00:01:38,970 here in your setup that lets us quite 42 00:01:38,970 --> 00:01:40,439 easily create this. So we'll just create 43 00:01:40,439 --> 00:01:43,470 a key called limit, and if we go back to 44 00:01:43,470 --> 00:01:45,780 the documentation it takes in an integer, 45 00:01:45,780 --> 00:01:47,820 a sample of that is three. So let's put 46 00:01:47,820 --> 00:01:52,200 an integer in, let's say two. So we put 47 00:01:52,200 --> 00:01:54,360 that in and interestingly you can see 48 00:01:54,360 --> 00:01:56,070 something going on here. So as we've 49 00:01:56,070 --> 00:01:58,590 added this key in this value here the 50 00:01:58,590 --> 00:02:01,200 URL appears changed. So instead of just 51 00:02:01,200 --> 00:02:03,960 being slash launches, it now has this 52 00:02:03,960 --> 00:02:06,960 question mark limit equals two. And so 53 00:02:06,960 --> 00:02:09,360 that's how query string parameters are 54 00:02:09,360 --> 00:02:11,160 encoded, they're encoded in the URL 55 00:02:11,160 --> 00:02:13,860 itself. And Postman 56 00:02:13,860 --> 00:02:15,660 takes care of this for us. So as we 57 00:02:15,660 --> 00:02:17,370 create these parameters it automatically 58 00:02:17,370 --> 00:02:19,860 adds them to the URL for us, and we can 59 00:02:19,860 --> 00:02:22,410 see if we delete this here. So if we 60 00:02:22,410 --> 00:02:25,410 remove this query that parameter is gone 61 00:02:25,410 --> 00:02:28,740 from here as well. And so it nicely syncs 62 00:02:28,740 --> 00:02:30,480 this up, so we can type it right back in 63 00:02:30,480 --> 00:02:35,160 here if we want, so let's do limit equals 64 00:02:35,160 --> 00:02:38,640 two. And it has added it back down here 65 00:02:38,640 --> 00:02:42,060 for us as well. So Postman gives us this 66 00:02:42,060 --> 00:02:44,120 flexibility to do it either way, and 67 00:02:44,120 --> 00:02:47,130 helps us with setting this up. So let's 68 00:02:47,130 --> 00:02:48,840 take a look at another parameter, let's 69 00:02:48,840 --> 00:02:51,209 go back here, let's do this one, we'll do 70 00:02:51,209 --> 00:02:54,030 order and we'll give it a value of 71 00:02:54,030 --> 00:02:57,870 descending DSC. So let's put in our key 72 00:02:57,870 --> 00:03:03,989 order, and our value des see. Now we can 73 00:03:03,989 --> 00:03:05,910 see that Postman again has encoded this 74 00:03:05,910 --> 00:03:08,370 into the URL for us, very handy it's 75 00:03:08,370 --> 00:03:11,190 added the and here to concatenate these 76 00:03:11,190 --> 00:03:14,220 two queries together for us, and set that 77 00:03:14,220 --> 00:03:16,020 all up. So it's quite nice the way that 78 00:03:16,020 --> 00:03:19,380 Postman handles this. So the examples 79 00:03:19,380 --> 00:03:20,970 that we've looked at up until now our 80 00:03:20,970 --> 00:03:23,519 examples of query parameters, or query 81 00:03:23,519 --> 00:03:25,500 string parameters, but there are a few 82 00:03:25,500 --> 00:03:27,209 other kinds of parameters that can be 83 00:03:27,209 --> 00:03:29,880 used in an API as well. So if we go back 84 00:03:29,880 --> 00:03:32,610 to the documentation again, and we scroll 85 00:03:32,610 --> 00:03:36,660 down let's go look at this one here, get 86 00:03:36,660 --> 00:03:39,630 one launched. And you can see here in the 87 00:03:39,630 --> 00:03:41,940 URL it's got these squiggly brackets, and 88 00:03:41,940 --> 00:03:44,549 flight number. So this flight number is 89 00:03:44,549 --> 00:03:46,440 considered to be a parameter. So this 90 00:03:46,440 --> 00:03:48,600 gives us the launch info for one 91 00:03:48,600 --> 00:03:51,269 particular flight, given that flight 92 00:03:51,269 --> 00:03:53,459 number. And so you can see here that's 93 00:03:53,459 --> 00:03:55,799 the parameter, that's the sample. So this 94 00:03:55,799 --> 00:03:57,810 is another kind of parameter, and this is 95 00:03:57,810 --> 00:04:00,570 called a path parameter. Now there's also 96 00:04:00,570 --> 00:04:02,700 a type of parameter, that's called the 97 00:04:02,700 --> 00:04:04,380 header parameter we touched on those 98 00:04:04,380 --> 00:04:07,260 already in the authorization. And in 99 00:04:07,260 --> 00:04:09,299 Postman you can create headers here, 100 00:04:09,299 --> 00:04:12,299 quite similar to the query parameters 101 00:04:12,299 --> 00:04:15,150 but these don't get encoded in this, they 102 00:04:15,150 --> 00:04:17,548 get sent as a separate header thing on 103 00:04:17,548 --> 00:04:20,070 the request that gets sent to the server. 104 00:04:20,070 --> 00:04:22,500 So the primary way that you would use 105 00:04:22,500 --> 00:04:24,240 these typically is with authorization, 106 00:04:24,240 --> 00:04:26,940 although in Postman you're probably 107 00:04:26,940 --> 00:04:27,850 going to set up your 108 00:04:27,850 --> 00:04:30,580 on the authorization tab. And then 109 00:04:30,580 --> 00:04:32,470 there's another type of parameter that 110 00:04:32,470 --> 00:04:36,580 is known as a request body parameter, we 111 00:04:36,580 --> 00:04:37,900 don't usually use those with GET 112 00:04:37,900 --> 00:04:39,880 requests but we will dig into them a bit 113 00:04:39,880 --> 00:04:41,470 more when we get to POST and PUT 114 00:04:41,470 --> 00:04:43,330 requests. So that gives you a quick 115 00:04:43,330 --> 00:04:45,670 summary of how to use parameters in an 116 00:04:45,670 --> 00:04:50,080 API. And in the next video, we're going to 117 00:04:50,080 --> 00:04:51,880 get you set up for a testing challenge. 118 00:04:51,880 --> 00:04:54,700 So we'll set you up for a find the 119 00:04:54,700 --> 00:04:56,650 secret challenge, which is a challenge 120 00:04:56,650 --> 00:04:59,080 where we will find a secret that's 121 00:04:59,080 --> 00:05:01,900 hidden in the test API, hope to see you 122 00:05:01,900 --> 00:05:06,900 there.