WEBVTT 00:01.530 --> 00:07.170 So before we go too much further, let's recreate that right, Jason Helper function, because we're 00:07.170 --> 00:11.880 going to be doing this all the time and it might simplify our lives or actually will simplify our lives 00:12.690 --> 00:13.690 so we can help her start. 00:13.710 --> 00:16.860 Go inside the CMD API folder. 00:16.890 --> 00:23.010 Let's create a new function with a receiver of app application, and we'll call this one right, Jason. 00:27.630 --> 00:32.490 And it will take a few arguments, a response, right, so we have something to write to. 00:35.550 --> 00:42.240 But also take the status, which will set the status code for the response, whatever we want to turn 00:42.240 --> 00:46.170 into Jason, and we don't know what that's going to be, so we'll just make that an interface. 00:48.330 --> 00:50.400 And finally, we might want to send some headers. 00:50.400 --> 00:56.160 So I'll create a variable called headers and I'll make that very ADIC so it'll have zero or more headers. 00:58.710 --> 01:01.770 That way it becomes optional and this might return an error. 01:02.850 --> 01:03.950 So very straightforward. 01:03.960 --> 01:08.550 All we're going to do, first of all, is create a variable called out and we'll check for an error 01:08.550 --> 01:12.180 and we'll use Jason martialing debt just like we have before. 01:12.180 --> 01:12.870 And in production. 01:12.870 --> 01:19.500 I would use Marschall, of course, and we're going to marshal data with no prefix but leading tabs 01:19.680 --> 01:21.750 when we format it and we'll check for an error. 01:22.650 --> 01:25.590 If error is not equal to nil, then we'll return the error. 01:28.140 --> 01:32.650 Otherwise, next thing to do is to check to see if headers has been set. 01:32.670 --> 01:38.370 So if the length of headers is greater than zero, then we want to add those headers. 01:38.370 --> 01:43.700 So we'll just say for K for key and V for value is a sign. 01:43.720 --> 01:47.670 The value of range through headers index is zero. 01:50.040 --> 01:59.700 And each time we looked for this we'll just say header at index K for key is equal to V for value. 01:59.850 --> 02:01.890 That way we can set all the headers we need to. 02:02.220 --> 02:06.630 And of course if that option of value was not set, then this just gets skipped. 02:07.470 --> 02:21.180 Now we just write it down header and we set the content type two application, Jason, and we write 02:21.180 --> 02:32.370 the status write header status, which is just an end and status has to have a type up here that's going 02:32.370 --> 02:32.930 to be an aunt. 02:36.280 --> 02:38.980 And we write the letter W, right? 02:40.090 --> 02:45.210 Oh, so we read our data, there's our Jason and I, we return now because there's no error. 02:46.420 --> 02:50.470 Let's give this a comment so we'll say that. 02:51.250 --> 02:51.510 Right. 02:51.550 --> 02:54.250 Jason writes, Arbitrary. 02:58.210 --> 03:01.270 Data out as Jason. 03:01.970 --> 03:03.620 OK, this isn't being used anywhere. 03:03.640 --> 03:04.410 So let's go use it. 03:04.420 --> 03:10.000 Let's go back to our handlers dash API and we'll simply get rid of all of this. 03:14.560 --> 03:19.730 And instead, we'll call and I'm not going to bother with doing anything with the air right now. 03:20.230 --> 03:25.660 We'll call after right Jason and give it to necessary parameters, our response writer. 03:26.110 --> 03:32.950 And in this case, it would be HTP the status, OK, and the pilot. 03:33.160 --> 03:38.710 And I'm not setting any headers so I can leave out that optional fourth parameter and that should actually 03:38.710 --> 03:39.040 work. 03:39.040 --> 03:39.880 So let's try this out. 03:40.090 --> 03:42.760 Let's start our application like start. 03:43.240 --> 03:47.290 And if everything went as expected, we can go use that right. 03:47.290 --> 03:48.340 Jason, everywhere. 03:48.340 --> 03:56.140 We need to go back to our Web browser, will open the JavaScript console, click on login and log in 03:56.230 --> 04:00.910 with any data we want me at here dot com and some password. 04:01.090 --> 04:03.280 And I should get my response over here. 04:03.280 --> 04:04.060 And I do. 04:04.270 --> 04:06.520 Error is false and message success. 04:06.730 --> 04:11.260 So that works as expected and this will greatly simplify our lives as we move on.