1 00:00:00,860 --> 00:00:02,950 I'm back inside of my blog context. 2 00:00:02,990 --> 00:00:07,000 J.S. file taking a look at the blog post function we just put together. 3 00:00:07,000 --> 00:00:11,800 So we're going to essentially update all these different action functions that we have so add blog post 4 00:00:11,830 --> 00:00:17,920 delete and edit twelve make requests to our back API it should be a pretty straightforward process so 5 00:00:17,920 --> 00:00:19,030 let's get to it. 6 00:00:19,230 --> 00:00:22,450 I'm going to first start working on ADD blog post right here. 7 00:00:22,450 --> 00:00:28,030 So inside of ADD blog post first begin by commenting out the dispatch and callback inside there. 8 00:00:28,030 --> 00:00:32,710 We're just going to worry about making our requests to create a new blog post right now. 9 00:00:32,720 --> 00:00:34,920 Oh then mark this function as a sink. 10 00:00:35,200 --> 00:00:43,830 And then inside we'll add in our request using axioms so I'll do in a wait Jason server dot post remember 11 00:00:43,840 --> 00:00:49,110 anytime we want to create a record on our back end server we're going to make a post request to make 12 00:00:49,110 --> 00:00:55,620 a post to slash blog posts so I'll do a post request to slash blog posts. 13 00:00:55,860 --> 00:01:00,540 And the second argument is going to be the information or the data that we want to send to our server. 14 00:01:00,600 --> 00:01:05,730 So in our case it will be the title in content that we call this function with we're gonna send that 15 00:01:05,730 --> 00:01:07,440 along inside of an object. 16 00:01:07,500 --> 00:01:11,720 So we'll do title is title and content is content. 17 00:01:12,070 --> 00:01:14,280 As usual our keys and values are identical. 18 00:01:14,280 --> 00:01:20,770 So we can condense that down to just title and content like so so as soon as we run this line right 19 00:01:20,770 --> 00:01:26,380 here and make a request we should be telling our Jason server to create a brand new blog post let's 20 00:01:26,380 --> 00:01:33,520 do a quick test so I'll save this we can flip back over I'll go to my create form and then on the create 21 00:01:33,520 --> 00:01:40,460 form I'll enter in a title of newly created API post and some content. 22 00:01:40,690 --> 00:01:44,790 Remember we've not wired up our dispatch or the callback right here just yet. 23 00:01:44,800 --> 00:01:49,360 So when we click save blog post or tap it on your device we're not gonna see anything really happen 24 00:01:49,390 --> 00:01:50,790 on the screen right away. 25 00:01:50,890 --> 00:01:52,430 So I'll go ahead and tap that. 26 00:01:52,660 --> 00:01:55,240 And yes sure enough nothing quite happens. 27 00:01:55,240 --> 00:02:00,530 However if you still have your code editor open with your DB Jason File Open inside of it. 28 00:02:00,610 --> 00:02:03,880 Remember that's from our Jason server project directory. 29 00:02:03,880 --> 00:02:08,800 You might see inside there are blog posts array now has a second blog post inside. 30 00:02:08,860 --> 00:02:10,960 So that's the one we just created. 31 00:02:10,960 --> 00:02:16,660 Notice how he was an assigned an idea of to remember Jason server automatically assigns ideas for us 32 00:02:17,510 --> 00:02:20,530 to now to make sure that we can actually see this on our device. 33 00:02:20,560 --> 00:02:27,450 We could do a refresh of our application to get back to our index screen so to do so if you are on a 34 00:02:27,450 --> 00:02:33,570 simulator remember you can press commander or if you're on the android emulator you can it are and if 35 00:02:33,570 --> 00:02:38,970 you're on a physical device you can shake your phone and hit reload alternately a much easier way is 36 00:02:38,970 --> 00:02:43,580 to just make a change to your code and save it that will reload the application. 37 00:02:43,600 --> 00:02:48,550 Now I can very easily see my newly created API post is now visible on this list. 38 00:02:48,550 --> 00:02:49,920 Very good. 39 00:02:49,990 --> 00:02:55,690 Now that we've got that working let's try to uncommon it just the callback for right now we won't worry 40 00:02:55,690 --> 00:02:58,090 about doing that dispatch just yet. 41 00:02:58,090 --> 00:03:04,090 So now after we attempt to create our request and after the request is successful we should then navigate 42 00:03:04,090 --> 00:03:06,140 back to our index screen. 43 00:03:06,190 --> 00:03:15,090 So I'll save this flip back over and I'll make a third post I'll hit plus I'll enter in third post creation 44 00:03:16,020 --> 00:03:16,670 with some content. 45 00:03:16,680 --> 00:03:22,090 Once again and I'll hit on safe blog post on those so we do navigate back. 46 00:03:22,110 --> 00:03:25,510 But once we're back here I do not see the new blog post appear. 47 00:03:25,680 --> 00:03:30,720 So it's a little bit unexpected but at the same time it is kind of expected as well. 48 00:03:30,780 --> 00:03:35,100 So let's take a quick pause when we come back the next video we're going to figure out why we did not 49 00:03:35,100 --> 00:03:41,070 see this API or steamy the new post appear after we made our post requests even though if I once again 50 00:03:41,490 --> 00:03:46,210 check my DB Jason File here it is right here. 51 00:03:46,340 --> 00:03:48,260 The third post definitely was created. 52 00:03:48,560 --> 00:03:51,260 So for some reason it's not immediately appearing on the screen. 53 00:03:51,260 --> 00:03:53,120 So let's figure that out in just a minute.