Learn Live - Consume REST web services in .NET MAUI apps

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] thank you oh my goodness Matt we are back and we are fully remote this time yes we are episode six we made it we made it to the second hand James oh my goodness oh my goodness well I'm glad you know every time um Monique plays that video with the music it always a jump scares me and I'm just like it's on it's go time like oh like I wake up it's not as good you know it's here um I'm back you were live in the studio I thought icon weren't you yesterday all day long we gotta get there at six a.m nice 6 a.m Pacific time so that was still 6 a.m my time pretty early yeah it went through 5 a.m and uh my voice is back did some hosting introduced the different sessions had a session myself Whirlwind tour of azure and it was quite a whirlwind James you had a session too I did yeah we had a fun session on.net Maui plus Blazer hybrid me and Alon did uh and it was a it was a session about hybrid development hybrid because Alan was in the studio and I was not so I was here at home which was great and so it was like really true to form you know what I mean it's like we're gonna really amp up the full production value of just going all in on hybrid everything so it's fun and those videos will be out on the.net YouTube so if you're watching on YouTube right now on the Microsoft developer YouTube you can go to youtube.com forward slash.net d-o-t-n-e-t and boom you can subscribe right there and get all sorts of.net goodness we just put out some new customer videos and they're gonna be releasing all of the.net comp videos but we'll put up some slides about where you can be watching it now I'm glad that some people are here so we have some got Patrick and Katie is moderating in the chat woo love it Jose is back um hopefully more people are just going to watch this on demand later because hopefully everyone's just binging and watching all the cool.netcom stuff that's mine there's amazing stuff going on today I know this morning we had what's new in c-sharp 11 we have an Architects panel I don't want to advertiser.net conf too much but there's just a ton of good stuff going on there there's tons of good stuff but we got tons of good stuff happening right here because today we are on part six like Matt said earlier which is about consuming rest web services in.net Maui applications because there are things that almost every single application wants to do besides creating the UI is like do stuff with data and this week we're going to be talking about consuming rest apis or web services whatever you want to call them so things where you get data from the internet and then next week we're going to be talking about how to store said data into databases in the final part which is super cool and you can follow along by scanning that QR code or going to that very short aka.ms4 slash learn live Dash 22220 I got some airplane going on what's going on is that you can you hear that yeah it's an airplane going over mine bam welcome to Seattle wow yeah wow that's wild wow that microphone really picked it up I know that's amazing usually it doesn't pick it up but usually does pretty good at deer or noise canceling my immigrants are really low airplane I should duck I don't know if I go offline you know something bad happened oh no oh my goodness uh cool all right what else we got going on we got our good friend Katie Savage in the back moderating all over the internet thank you Katie for being here uh Katie's rad she's been with us and John as well moderating all six so far of these which is cool we got a DOT net conf going on we just talked about it today yesterday and tomorrow all the days happening on right now so go to dot netconf.net you can you can watch both streams at once if you want just yeah I know I get the view counts double double just mute one or you have a mixer one in one ear one in the other ear oh my Debbie you know the producers yesterday they did have you know because you hear the you hear they have like their whole separate Channel where the camera people are talking and then they have where the speakers are and so the producers had they had two different headphones going so they could hear everybody at once yeah oh yeah maybe maybe that's something we could do too we could do it we do whatever you want I'm in yeah uh yeah go check that out and uh what we're gonna do today instead of um doing our team's call afterwards we're just gonna go ahead and watch dot net comp together so we're just gonna go over there because that's happening I want to push people over there um but next week maybe we'll do a final one as well so we'll see how it goes there cool let's get into it like I said today we're gonna go through this learn module which is consuming rest web services in Don Maui applications um and really the main objective here is that we're gonna do a few things when it comes to making web calls which is first we're going to learn about how we can actually detect if our devices are online that's an important aspect of making a great user experience then we're going to consume rest web services and then finally we're going to see how we can take advantage of some native Network Stacks when using HTTP client as well there which would be cool hey Matt do you want to can you turn down your gain just a little bit for me you really are picking up everything huh yeah I can hear I can hear myself a little bit interestingly yeah that's crazy yeah give me let me turn it down we're working on Matt's setup by episode 25 we're gonna have clutch how's that it's not as much about yeah that's much better okay oh that's perfect that's Alan in fact yesterday during the the hybrid session that I did I had the same problem my mic was a little hot so like I had it so it's really true like so just a little bit like this this is what it was and he's like well Cam's like that's too hot so I turned it down to here and he's like that's perfect I love all the terms you know you're too hot you're too hot you know too hot yeah well at least he made me feel good about being wrong too hot or you're peeking yeah I could said you're peaking yeah you're peeking that's usually what it is because you say Peak because it's like up there it's still red yeah all right anyways let's do this uh cool so why do we care about this well we care about this because like I said in the beginning is that almost every single application not every application uses the internet I have a few applications that do not use the internet per se in fact two of my three do not use the internet um but uh but but for the longevity of apps that I've built they've all used the internet um in some Source right authentication getting data from the internet um posting data backs you're going to get data you're going to make requests back to it I mean you usually do these over HTTP requests so we're going to talk a little bit about that today and what that means specifically for developers uh and how we can start to do that into a.net Maui application there's all sorts of different you know um scenarios that you want to think about right because we have these mobile devices it's like this here right that is around and just because I have it and I'm here on Wi-Fi uh inside of my house I probably have pretty good internet maybe I could live somewhere really uh Rural and remote maybe I don't have super fast internet so we want to take into consideration maybe you know the size of the data that we're passing around are we downloading a bunch of big images um there's a big blobs of data are we paginating our data but also think about our driving around right like when I drive around um you know we're actually inside Mouse if I didn't have Wi-Fi like one bar I barely get any service when I go outside I get a little bit better service but if I'm driving through the mountains I don't have any story I don't have any data right so so there's these things to think about of detecting uh different network capability and and also just because you are online with Wi-Fi like detecting Wi-Fi doesn't necessarily mean you actually have internet I was inside of a Fred Meyers uh yesterday which is a grocery store chain and they have you know free internet because like inside is this big building on a really good reception so I'll get you know I'll get that and and get onto the Wi-Fi but you got to go into the page it prompts you to log in and like is that fast is that slow do I have it there's a you have it you're on Wi-Fi but then do you have internet type of things there's always different considerations to think about when it comes to it but um it's important because doing this stuff consuming rest Services no matter where they're at maybe you're hosting them up in Azure maybe you're hosting them locally maybe you're consuming another third-party provider of data I used to do that for meetup.com I had a Meetup client they have an API the nice part about doing this with.net and Maui is that it's a single API it's just a.net API which is HTTP client so if you've ever done any.net development in the past you know this hopefully should feel a little bit familiar besides some of the things that we'll talk about today specifically around mobile devices and desktop devices such as detecting network connectivity mat it's very important yep and that's the one thing about mobile devices or mobile apps you can account on your users eventually getting mobile with them and moving around like you said you jump into a Fred Meyers you jump into a Safeway you're in some grocery store deep inside and then no internet or like you said you're driving over the mountains spotty internet you're in Seattle which has one bar everywhere for some reason never know what speed you're getting or or whatnot so gotta check it out first do you know the best grocery store my new favorite grocery store um we've we've given shout outs to the Kroger brand and now also the Albertson Safeway brand you know my new favorite Grocery Outlet Bargain Market it's absolutely the best is that the one where you can find like you know right now you'll find stuff that was for Valentine's Day there no no that's what people think it's that's what people think here's what here's you know you know TJ Maxx like a Marshalls things like that TJX so what they do is like they they have buyers like they usually buy things in bulk and then the things that are sort of On The Fringe of Odysseys and all this other stuff so Grocery Outlet Bargain Market which is a great name is so long we call it um um grok is what we call it um Grocery Outlet um and when you go to Grocery Outlet it's basically like it's like a mini tiny Costco right um where let's say you go down the cereal aisle well when you go to a grocery store you have about a thousand different cereal options right at Grocery Outlet you got eight and there's like a bunch of them right there's like eight so what they do is they work for like it's like the Overstock type of stuff right but it's really cool because someone that does Atkins which is like a form of a easier a lighter form of Keto they have tons of Keto stuff because they just have all sorts of good stuff and Atkins stuff and all this other stuff but I'll tell you this much like a fantastic people it's overrated you gotta go check it out you'll have a delight and they also have tons of local stuff too local Brews local stop local local yeah I know you think you're like oh it's gonna be that no it's not it's not at all I love it it gives you like an opinionated framework of grocery shopping you have these eight cereals to eat and you're gonna like it it's going to push you into the pit of success exactly yeah so I mix that up between that and Trader Joe's because Trader Joe's my favorite anyways um let's talk about this detecting network connectivity there's all sorts of different connectivities on these devices right technically you could be communicating over Bluetooth mostly usually over Wi-Fi sometimes over cellular there's different cellular speeds there's different considerations in that as well additionally we want to be able to detect a network connectivity because like I said people often lose connectivity or um they might be on a plane or they might be traveling abroad and they don't want to use their cell phone data right so there's a lot of different options that are on here that come into consideration of why we want to detect our Network capabilities now I mean this makes sense hopefully yeah I mean we're on the go and you never know and the thing is though if you don't connect or check your connection and then you try to hit the internet you know what's going to happen and you don't boom you get an exception and your app crashes exactly don't want to have that that's yeah I was at a conference once and they did make you know the um the check they had the schedule up in the Json file on a website but they didn't check connectivity first and they just assumed like you did that people the school where they had it had a captcha first where you had to jump through they just assumed if you had Wi-Fi you're good to go but you weren't good to go and everybody was having crashed nobody knew where to go because they couldn't get their session agenda exactly yeah and this is and this is a good you know it's a screenshot of a you know an option that you sometimes see in in applications of of not only detecting you know at startup before you make the call but maybe when the connection changes I often see in mobile applications all sorts of different use cases sometimes it's a pop-up sometimes it's a nice friendly image there's lots of way of displaying this type of information to your users because often again you can you have to in your mind make a determination of okay even if we did store data in a database locally you know how do we do how do we display older cache data how do we notify the user is it okay if it's not the latest data or XYZ like how are we showing our users that information back and forth because often if you do have a user and they're logged in on multiple devices they're going to be synchronizing data so you want to make sure that those things are in sync too so it's important or maybe some of your application works offline some of it has to be online a good a good concept is Airline application right I was flying on an airline and you know to book a ticket obviously you need internet to do that but to to make sure I get my boarding ticket as long as I got it ahead of time I can go once I've checked in I can get access to that offline later because it stores that information later and it'll let me do that yep exactly or even something I already had to get a receipt later you might want to see the receipt and you're offline but download it at first so like it can kind of preemptively know what you want to do and download it beforehand but you might be offline later and you can see how this stuff gets really complex quickly when you start architecting an application when you have to take online offline into um consideration yeah so yeah luckily Dynamite makes it super simple because there are a bunch of cross-platform native apis integrated into dot ml itself sometimes it's referred to as Maui Essentials because it's sort of the evolution of xamarin Essentials that was now bundled into Maui but it gives you all sorts of things such as geolocation sensors and connectivity so for example here what we're able to do is actually check to see what type of internet access we have so we're able to come in and say connectivity.current and we can check the network access and the network access has a few different things it'll tell us if we have internet if we're on limited internet or if we have none and there's a few different network access enums in there I usually like to check if I don't have internet because if I'm unlimited or other things I don't want to handle those cases but this is a good one too where if I'm um here that's one option addition to network access you can also get the connectivity profiles and that's a nice one because you can then detect if you're on Wi-Fi or if you're on cellular so a good example there Matt is downloading those images so you may or are downloading a bundle of goods uh to your application so for example I use a mapping app it's called Peak finder grade app and it'll work offline and Stream in some data but what it it tells you is it says Hey like this is going to be like a 20 meg download you know you're not on Wi-Fi do you want me to wait like but if you're on Wi-Fi it'll just download there's no big deal but if you're not on Wi-Fi it'll it'll be like hey like do you do you want to do this and then often you'll see an application settings like in my podcast app um it'll say only download podcasts on Wi-Fi because podcasts can be really big and I'm on mint mobile um and I only have four gigs of data every month so this this stuff is really important to me not only as an app developer but as a user of applications yep and that's the use case I was thinking right away is like something like Spotify or any streaming music where you can download them keep them on your phone's device but you only want to do it while you're actually connected to Wi-Fi I want to hear more about Peak finder we can talk about it afterwards yeah but is that like all Trails or something I don't know it sounds kind of cool no peak finders is is different so Peak finder I like to get off on a ramble here Peak finder uh it's really cool so what it does it uses your phone you can hold it up in real time and it overlays outlines of all of the mountains and ridges and things like that um all over in real time so you know let's say you're out hiking you're like what is that mountain it's you'll help you find the peak yeah it's really cool yeah so it's one of those things complementary to like say all Trails where you're already hiking you're like what is that oh there it is cool and then it does the overlay and you can adjust the altitude too so if you know how high you are up anyways it's cool cool so not only can you check network access get profiles but you can also check if the connectivity changed that's kind of cool in fact yesterday in my session on blazerhybrid dawnet conf Alon and I showed this off and how we integrated this into a Blazer hybrid application with.net because it's all right here so this is really really cool because you're able to easily check when things are connected or not enough to do anything like I think this is really neat like I just showed you and talked about three different apis and three lines of code yeah kind of cool yeah you should I really love the connectivity change because it's actually monitoring what your device is doing in real time and it throws that event that you can catch and Away you go and that's something that you when you think about it initially when you're starting it's like how in the world am I going to handle going from offline to online there's a there must be a lot of platform stuff that's going on and how can I do that Molly Essentials does it for you now there's one thing I wanted to call out before and you kind of did mention that James is that Maui Essentials is now bundled in xamarin Essentials before was a nuget package you just get it now you don't have to do anything to um add it any longer it's all in there now on the documentation specific I'm going to open up the project we talked about yesterday in the um inside of of some of your application so here in the in my that's the air quality app that we built um you can go enter to your platforms let's say on Android in the documentation for any API you might need to add some permissions right so here for example there's access and network State and internet so those are ones that are important because you need access to those things I think you actually only need access network state but if if you're going to make an internet request you also need the Internet permission and which is default so these These are in the template by default which is nice you don't need anything on on iOS or um or or Windows for that but because you're accessing that and then what what we did is we done at Maui has its own iconnectivity interface so behind every.m Maui API is an interface and what we did is because we're sharing code between a Blazer website and a Don and Maui application we created our own little connectivity contract here that I can peek into and you can see it's just like a little little one here that sort of abstracts it but this is what you would do is basically here's the the connectivity here's the connectivity changed and here is the if it has access to the internet and if I if I go in here and do Dot you can see there's there's local so if you only have a local access there's internet there's constrained internet there's also unknown as well so if it's unknown there's that but if it has internet it has internet it's connected to the internet with full access to make a web request which is quite nice but that's that's it like that's really minimal amount of code to to check those things out cool now let's let's ramble a little bit more James we are now in a Blazer hybrid application show where you're consuming that because it's you're doing it in Razer right yeah so we're actually sharing some components here right here and that's being consumed we have our connectivity here and we have this little is connected uh up here which is quite nice yeah so this is amazing though if you ask me so you're using c-sharp code in a platform specific manner that same code that you would use in a Maui app but we're using it now blazerized and we're going to create a native app out of it because it's Blazer hybrid exactly we kind of moved easily from what we were talking about kind of but kind of yeah well we only have one exercise so I want to kind of like show it in a real world application we're gonna we're gonna walk through it as well but anyways you kind of see it which is cool yeah cool so yeah yeah very cool now let's check Matt yeah boom I can go to aka.com forward slash polls that's a good URL glad they grabbed that we've got a few questions for y'all which of the following is the best reason to check if you're connected to the internet before running Network code that's a great question is it a you don't want to waste Resources by performing operations that aren't going to do anything B you want to provide a good user experience if network connectivity is limited or unavailable or C to establish a connection if you're not currently connected all right that's a funny one you know what any of these are like yeah sure you're right well see if you're not currently connected well I guess you could prompt the user and say hey turn your Wi-Fi back on so I guess no that could be legit it's not the answer but it could be legit and a probably you know waste resources nah is that the best reason though yeah there we go is it the best ah there it is the best reason yes read the question Matt read the question so it must be B you want to provide the best possible user experience and everyone agrees 100 voted for beef all right how about this one suppose you're oh this is a long question suppose you're writing an application that a user can run while traveling in a vehicle that sounds I do that all the time I'm always in a vehicle the vehicle enters a tunnel I'm also doing that all the time that's like me just in and out of tunnels the device might lose internet connectivity which member of the connectivity class should you use to detect a change in network connectivity the network access the connection status or the connectivity changed event you know what can I disagree with the premise of this question okay you shouldn't be using up your your phone while you're in a vehicle especially in a tunnel right there should be a d suppose you're suppose you're writing an application where you're passengers all right are using yeah that's a great point you know or you know you know yeah exactly so everyone's voting here for the last one it's an event it changes other ones are properties uh there so this is the to you're detecting it right you can you can check at any given time the the network access connection status is not a property so that's the thing that does not exist so hahaha there's that but connectivity changes now connectivity change I want to mention here that connectivity change will not only trigger when things happen to lose internet connectivity but also when other events happen so for example if uh the user connects to Wi-Fi or deactivates Wi-Fi or or goes into different modes it's not only the connection status it's a connection type so the in the event arguments that come back it'll tell you the current Network status whether that be connected or the profiles as well cool yeah cool all right let's continue there's a bunch of slides and then there's one big demo so that's a big thing yeah so let's talk about consuming rest services with HTTP clients so we talked about rest services or rest apis or apis or web apis or apis apis there are all sorts of apis normally rest apis we can Center those to be verb based and we'll talk about the different verbs here but normally we think about these as returning Json but they don't have to return Json they could return XML or they could return different media uh just a blank string some number it could return anything in it you can also post data to it it could return a stream of data all sorts of different things but normally we think about them as Json things but rest is built in um it's built on top of the HTTP protocol and Maui apps and actually all.net applications use the HTTP client so today we're going to learn about the HTTP client and how to call rest services and this is important because if you you can take this logic of this code and share it anywhere you can share it in any application literally in this not this app and the app I just showed let me bring it up again over here in this app that I just showed which is this air quality app to talk about that this is just.net code inside of uh of this one application I have a little bit of code that does make some restful service calls this data service so there's our HTTP client we'll talk about that in more detail but this thing is being shared between a a Maui app a teams application a Blazer application and A team's bot client so it's being shared everywhere it's everywhere right so you can really pull it anywhere so it's just HTTP client magic under the hood yeah and that's another thing glad you pointed it out like you did James is that you're not doing anything special even though you're calling iOS or calling Android dot net it's just HTTP client at yourwriting.net code here boom it's just like that just like you just said it's part of system.http it's built right in now up top there that's a mobile device that's the app but that could be a desktop app it could be a web uh web app it could be a website it could be it could be literally anything any.net client could be a command line application it could be anything it sends a request and it gets a response back boom boom and it's all asynchronous all built in under the hood so we like to call these things crud operations create read update delete crud if you will um but specifically these crud operations are kind of more similar to a database but they map pretty well to rest verbs is HTTP verbs you'll call them which are post get put delete there's also patch we didn't put it on here but um but that is also another one as well which we're not going to talk about but mostly these are what you'll see in general which is uh post means you want to create a new resource get means you want to retrieve resources it could be a bunch of resources or details about a singular one put means you want to update a resource and then delete means you want to delete a resource yeah yeah pretty straightforward so you you send these requests up and they'll also send a request back so this is sort of what that looks like is the HTTP client and is communicating with your app the HTTP client does all this stuff over to your rest service and then it sends data back usually codes or sometimes data back too like for example you might post um something back and it might return an updated item to you so for example maybe it inserted into the back end database and then it may create a new resource and then give you back like an identifier so you can update it on your end too cool here's a bunch of words on a screen um but basically here's the important part of it when we create a new resource we can send and use a bunch of different things we can send messages asynchronously we can get strings asynchronously and we can pass this thing called an HTTP request message so we create an HTTP client we're going to call that a client let me create a message that's a message we send that over in different forms there's built-in helpers to pass Json so if we wanted to send data across the wire right we send it in a uniform way so there's actually something I saw called Json content.create and it'll create a message based on uh Json and then we're gonna send that up in that um and get back a HTTP response message and that response message um can it be many things it can be successful it can be not successful it can return error codes a bunch of different things back to us um because again we're talking to the HTTP client and the HTTP client is then talking to the web request right so that's important is is the HTTP clients like a broker in between right it's like if I go to the bank to an ATI if I go to the ATM it's like an ATM okay an atom if you will you go to the atom I like to call him an atom so you go to Adam and you say Adam here's twenty dollars please put this into my bank account and then what happens is Adam is going to go talk to the back end service it's going to take your money but then later on someone's going to take that money right it's gonna return return a success code and then later on someone's going to take that 20 Bill and put it directly into your your your you know I think with every account there's a box that they have that has your money in it and there's like you know it's there so someone's going to take it they're going to drive it to the other bank that has your specific box in it and then they put the money in the Box yep you're from them right yeah you're from the Midwest right so you remember time machines yeah yeah so like we always call ATMs time machines because that was the company that owned all the ATMs in the midwest except when we went out of the Midwest and you would ask somebody Hey where's the time machine they wouldn't look at you weird and ask when you want to go so it was just yeah that's great we're rambling so this is how you do it like I just said so here um you can easily create a new HTTP client um you're going to create a new HTTP message and you can say post there's even easier ways of doing this too so there's some built-in helpers we're Explorer today but this is at a base level as easy as you can do it you can create an ATP message we're going to say it's going to be a post we give it a URL we tell it what content to do and then we send it up asynchronously and get a message back but there are some helpers as well that trim down the code yeah at the same time you could be even more succinct than this if you wanted to um I like using the HTTP request message because you can start adding in authentication to it as well you got to access all the headers if you wanted so this was perfectly fine you could be more succinct with the HTTP client because there's a jake get Json request method I forget what the actual method is but there's a you can get it back quicker than what this is with less lines of code but it does the same thing exactly yep so easy peasy so um so for example we can also like this was about creating a new resource but we can read a resource as well same thing but we can use the HTTP get method so here we're going to actually go and say hey I would like to get a string asynchronous back and this will handle everything back to us the URL we can also like you said add additional metadata onto our request so here we can add on that this is going to reset accept back Json so this is actually important because your web server might have options in your get to return let's say XML or Json so you might want to say hey I would like to request back Json you might also want to add some other headers or properties on there like version versioning for example you can say please give me version 1.0 of my API version 2.0 because the server may say if you don't give me anything I'm going to decide for you so there's a extra metadata that you can add onto your HTTP client as well so do you um update you guessed it you're going to do a put it's exactly the same as before that's kind of nice like literally you know this code there's a post you see posts there htw message post it's the same uh except for it's put that's it yeah do it a little bit when the semantics just kind of push you right into it and you're really just relying on whatever the API author gives you they're saying you know what I want to have a put for this particular method you gotta all right I'm gonna create a message does it put yeah I'm at doing whatever they want now a lot of people ask post put patches all these other things you know the differences between post and put are fascinating right uh post is to post a new object and put would be to update right so if you repeat a put the resource would be updated over and over again um um but if you do a post several times it would be technically you're asking it to be created multiple times by the rest service so this is fascinating because I have seen people like not even have a put verb and just like say oh we're only going to put posts and you post and we'll put an end point that says slash update and then give me information so double check your back end right like the verbs are the verbs it doesn't mean that the service implemented the verbs correctly right yeah and then you get to a patch now I think the difference between a put in a patch is a put will do like overwrite the entire object or patch just does certain properties yeah it's like yeah patches like I changed this one property yeah yeah so but yeah delete delete you delete it and you're done easy to explain yeah easy to explain now here for example like you know you're you'd pass it some sort of information in this URL like an identifier um as well so let's kind of talk through that today because like this is It's just URL but you know based on what your back end is doing you have the delete verb but like you know what's actually sending in there so of course you're going to get a response back and you're going to handle the response so you're going to make your request and send async so you can see right uh here there's the send async and then basically you're gonna you can do a few things you can get the error code you can ensure that there's a success status you can actually just check the the return code too that's an option here you're going to ensure success um this is a nice one because if it if you just want to make your your your flow easy and not have to check is it success here's the different error codes this will throw an exception an HTTP request exception so for some reason you weren't authenticated or the back end uh rejected it or um you don't have internet or something like that you're throw an exception back else what you can do is you can do this response content read as Json string additionally built into system text Json there's helpers to automatically deserialize that information back I don't know if we're going to cover that today but we should update the module to do that that's cool a lot of people also ask hey should I create a new HTTP client should it be a static should it be this should it be that doesn't matter um you know the only difference would be is feel free to create new HTTP clients based on the contacts that you're sending them in in a mobile application their native Stacks are handling it for you they work a little bit different than a traditional um you know website and things like this for the scoping of it but Miguel told me a long time ago that it didn't matter so I just always believed him so there's that cool let's get to sub questions those which HTTP verb should use a create a new resource resource post put or add go to aka.ms4 slash polls do you think the uh the the designers of all the HTTP verbs specifications made everything with a p on purpose like post put patch yeah I do yeah I think because in all three of those instances those are all two like do something with the data that updates or inserts it into the database so I think like it I think I think so but I'm talking with the peas you know get that alliteration going post put patch but it's funny because actually it would be like patch post put alphabetically yeah [Music] uh let's see anyway um how are we doing how are the how are the results coming in I should have that open I don't know it didn't come in yet is it up set up it's loading all right oh there we go okay we got six votes for post yes all right cool which method of the HTTP response would you call to verify an HTTP Crest was successful is successful ensure success status code or check status code interesting we only showed one of these in the code yeah so Maddie and I were joking around yesterday that whatever we do we don't like to be brief about it when we name things so that'll be my hint here you like to be very verbose there you go and everyone is correct in the polls five out of five all right let's talk about some other stuff here before there's a lot of slides today um I think I wrote this and I think I ripped out a bunch of like oh their Partners put it all in one so one big exercise let's talk about some platform specific features before we actually get into some of the demoy stuff uh here and actually build and use this stuff is that uh HTTP client is an abstraction right over just HTTP requests um that we just showed however different platforms like iOS Android Mac or Windows might enforce some different let's call them not requirements but specifications or restrictions uh security things for example a good case of this is that by default on newer IOS and Android operating systems nearly all of them now your application cannot make http requests to an HTTP non-secure website so you have to be https out of the box so you have to have the search you have these things this actually does make it very complicated to debug things locally for localhost and loopback because those are your normally debugging HTTP because asserts and all this other stuff but by default they enforce basically newer https and TLS requirements onto the stack by default now I would say modern day this usually isn't a problem however you might run into scenarios in which that you run into these problems like I only have an HTTP thing or in debug mode I want to like allow certain IP ranges that I'm communicating with or you're writing an app internally right and you have an endpoint that's just HTTP or some IP address and you don't have https on there so there's these different requirements and security things that are happening um most of the time https or sorry HTTP client will do the right thing for you but you need to be aware of these other things on the platform such as on iOS the app Transport Security or ATS as we like to call it and what ATS does it is the one that specifically requires everything to be done through the native Network stack and use TLS 1.2 or above but it is configurable uh as well so inside of the info p list you can modify this and edit it I like to edit in the XML editor um there is an info p list editor as well as well if I like to do it here and this is what you can do so for example you can set different basically um requirements that your application needs as a workaround so you can exclude domains you can give a TLS exceptions right by default TLS 1.2 is required but if you have something that is running TLS 1.0 and doesn't allow 1.2 you might need to have an exception inside the stack as well there is an option to just say turn off everything which we don't recommend but that sometimes I do that in debug mode for example because it's just easier to work with and then I turn that back on and you know there so you can be aware of that you can basically turn off everything but there's a lot of different settings in here if you need to customize it down the wire if that makes sense yep but key is that HTTP client then will essentially pick this up and then do the right thing for you after you specified this yeah and there is one like I said there's a inside of here instead of like doing domain there's one called uh NS allows arbitrary Road loads and that one is you can set it to true that's like allow everything however you know Apple has said perhaps down the line this was like six years ago so maybe down the line um that they'll just not allow apps that do that to do that and be more specific and granular so be aware now something is very similar and true about Android that there's also security models around network communication and specifically it's not an as granular but it's still pretty granular it's mostly around clear text traffic or HTTP versus https traffic and you can enable this it's actually done in an XML file so it's it's not done in your Android manifest file it's not in a separate file that gets bundled into your application and it's specifically in resources slash XML inside of your Android folder and it's um we call you can call it anything but I like to call it Network underscore security underscore config because that's what the Android documentation did and calls it and you create basically a file that looks like this on the top which is a bunch of different XML attributes for network security configuration and you can say that the it allows clear text traffic you can allow specific domains you can allow everything there's a bunch of different settings there I believe on the application in the Android manifest which is shown on the bottom you can actually just say allow clear text traffic for everything instead of specific domains but we wouldn't recommend that because of security implications there and this is what you would set so basically your Android manifest file will reference this um network security config and you can set it up that way so you can see for example the debug debug the default debug Port is a good example here uh when you're running your Android emulator it's not running localhost it's actually running on 10.0.2.2 fun fact port 55555 five there um and because it's an emulator not a running on your machine you you can enable that and then you could debug locally on HTTP and go from there and the reason you might want to do this just because of certificates and things like that it gets a little bit tricky on emulators um so here this is what we just said you know there's a bunch of different configurations here if you're using asp.net core on your back end you might want to comment out this use https redirection specifically just in debug mode because that's going to enable you to more easily talk to your Android emulators and simulators that's normally what I do when I'm debugging locally so you can put a a conditional compilation say if debugging turn that off and then you would set up all that stuff in general and then because emulators and simulators run differently based on the ports you're going to need to do a little bit of platform configuration here if you're running in debug so normally you've already deployed your back end so it's out there into the internet but you might want to do something like this which is detecting if you're on Android then you would want to specify the HTTP with the IP address or localhost so iOS and Windows and Mac can all talk to localhost Android emulators cannot because there an emulator and there's a different network stack all up yep yes cool gotcha yeah amazing Android emulators there's always something with them right they always have to it's like a little itty bitty Docker container running it really is it runs its own you know Jade it's all in there it's all bananas all right cool so let's get into it let's actually do an exercise what we're going to do is almost everything that we just talked about so we're gonna like basically pretend that we're building an app um that Engineers use on customer site visits that basically need them to look up details for electrical components so we're gonna deploy a rust back-end web service we're going to figure out how to do that um for free which is kind of cool we're gonna take a look at our Maui app we're going to examine our web service code we're going to sign into our service and then we're going to do some gets posts and delete so we're gonna do all that so we can update the back end in the database so let's do that uh over here so I'm going to open up uh really quick here the learn module that we have so this is a really cool thing we haven't done this at all but some other learn modules training modules I should say on Microsoft learn training yep Rebrand Rebrand uh here training live is what we should call this um I guess we are still learning live so yeah it's still alive it's this thing called The Sandbox so um what we have here is um in the last 24 hours I did test it yesterday you have 20 sandboxes so you can think of it like this as basically a Sandbox enables us to deploy code um in Azure resources uh for free um for a temporary amount of time they reset after two or three hours um so you have some time to do it and they're integrated into this so this is really neat this is one of my favorite sort of parts of this is that you can go in and you can activate the sandbox you do need to be logged in right yes and I'm gonna it's gonna it may have you authenticate and do some things here so here can you bump up here it's not James on this one no all right there you go here we go yep so this is going to do a bunch of stuff for us behind the hood and it's actually going to give us an Azure Cloud shell now the reason that we're going to do this is not anything specifically we're not going to do anything in the Azure Cloud shell this is my this is why we're but why this here's why we're using it we're using it oh four hours nice we're using it because we're actually going to deploy a back end that we can communicate with in our mobile and desktop applications and this is nice because instead of just trying to figure out all the localhost stuff what we're going to do is deploy it so we have a real URL with https so you can put it on a device you can put an emulator a simulator locals it doesn't matter so we wanted to go this route because we're not learning about deploying the back end there's other training on using Aspen on a core to do that what we are caring about is how do we integrate that backend into our website and what's nice here is that now we don't have to maintain these resources and worry about the data in it this is temporary to you so and you get 20 of these you know it's super cool that you're actually calling out to Azure here you're calling out to a real live website that we could actually go browse to that you could actually write a regular web app Blazer app yeah call too it's the real deal so I'm just going to copy these things so we're going to deploy our back end so I'm going to copy this and then I'm going to paste it in so the first thing that that's going to happen on the server so this is inside of azure Cloud shell is we're going to clone the GitHub repository and then we're going to navigate to it so this is nice Matt I think wrote this or someone else did I don't know someone wrote this um and then what's cool is there's a there's a there's a shell script in here so that's going to do all the stuff for us so you don't really need to care what's in it but what this is going to do is it's going to handle automatically creating all of the resources for us so we can see it's actually going to create this web server it doesn't exist your web server will be different than my web server but if you um next go down here we can clone this repository ourself as well so I've done that and we can take a look here at it so when we look at this code specifically there's a server part and there's also let's add the bachelor let's look at what's happening on the servers it takes a few minutes to deploy so I'm going to add an existing item here and inside of here we're going to look at this uh init environment script so this is really neat so this is going to basically declare this startup it's going to make to see if resources exist it goes off it it actually creates an Azure resource it gives like random app name it creates via AZ web app up a brand new website and then when it's all done on the free SKU which is nice it's going to give us a full URL so it's going to bundle up take our resource and then deploy it to our back end which is really nice amazing yeah it's pretty cool I think I might change this to use the Azure CLI so we can run it from anywhere nice pretty cool that's very cool nice anyway that's what that's doing cool and on the back on the back end um what's happening here is that there are specifically um some parts so here's what this looks like we need to update this uh to make it look a little bit prettier but there's a part ID a part name a list of suppliers um there's uh some URL references based on that ID there's this parts factory so I think it's just an in-memory database it's not doing anything special basically at this point but what it's doing is it is um specifically I'm creating this data and what it does is it sort of creates a a list of um parts for users based on their authentication tokens and there's a bunch of default ones here so it just creates some some default data puts it up when it starts up and then then puts the data into a database and specifically there are a few controllers so there's a login controller and this is not how you would create a login control there at all but all it does is is is you call a login and it gives you a new authorization call back but you can imagine that you're calling into Azure ad or you know or you're calling into something it doesn't matter you just want to kind of show this off but then there's a parts controller and this here is going to give us a get so it authenticates make sure we're authorized it returns unauthorized if if we're not authorized and then it will go and get the user parts same thing here there's another one that takes in an ID so a string identifier it goes off it looks to get the specific part and then return it back if it exists and then over here there's the put so these are this is the back end that we're calling so we're looking to make sure that it's authenticated it's valid the part ID exists and then it will go off and create that for us and then there's a post as well so here since it's a post it's only going to make sure it's valid and it's going to create a part ID for us because it's the back end into the database and then it's going to go ahead and there's also a delete here so these are the things that we're going to call automatically this should be delete not post which is funny there and that's pretty much it for the back end it's very very simple um and it just starts up and there's actually a Swagger UI um automatically on it too so let's see if it's deployed it has cool so I can actually click on this that was pretty quick not bad um it's running on.net7 but but a DOT net six app so funny so when you go to the URL nothing's going to be there but if you do slash Swagger it'll bring up the Swagger UI that's kind of cool right amazing amazing now oh die I love Swagger too now fun part here is that um you can uh log in and this is going to give back a uh authentication token which is nice um and we're gonna we're gonna set up some code to automatically do it for us but we could try to like get this back I actually don't know how to do it in here so I don't think you can actually you can actually just type right into the request body go down go down here if you want to get you could just get it I was giving a 401 because we're not authorized oh you got to put it into the um scroll back up scroll back up oh where are you all right so oh you know what the Swagger isn't saying that he needs it in uh headers so they can't actually put it in yeah Swagger definition should be a little bit better yeah so we're going to improve that a little bit here but we're gonna create an API that actually calls us there's actually a bunch of new stuff that they announced yesterday at.net conf to actually really simplify this too so we're definitely going to do that as part of it but you know we don't want to change everything two seconds before it came out but you can see here like this actually we're calling it but not passing of the authentication so it returns um you know it's not authorized basically so it's there cool all right so now what we're going to do is we're going to go ahead and take a look at some of this stuff in our code really quick I do not want teams to open there we go cool we're going to take a look at the.net Maui application which is over here so let's go ahead and close this down perfect now what we're going to see is inside of here we still have we have a basically a scaffolded application so we have some data so we have a part so here is a part so um this has kind of same information but it's using some mvvm stuff and we say it's serializable and I'm going to say it's a part name and then it's a supplier and we have part types and we have all sorts of different things inside here very similar but you know we might be just uh displaying the data a little bit different the parts manager so this is what we're going to implement today so often you have like a data manager in our data class so the parts manager is going to communicate to the restful back end and um and we have a get client which is going to return an HTTP client a get all and add an update and delete so um almost crud but we're almost hit add delete yeah it's kind of krudish we get get all which returns some parts ad is gonna is gonna add it to the back end update's gonna update and delete's gonna delete so there's that cool so that's the parts manager that's what we're going to implement today which is quite nice and then if we look at the parts page this is pretty straightforward um we have over here is we have a button that says add new uh parts we have a refresh view over here that is going to allow us to call load data we have a collection view that's going to list the selected parts and that we can tap on them and get more information and we have a data that just puts out some different information about that part so that's pretty straightforward and then on the ad um part page when I tap on it we have some information about the uh the the item and then we have three buttons so save delete cancel that's going to call some code in our view model so if we look at the parts of you model we can see that there's just standard mvvm so we have our parts collection we have an is busy here this is pretty verbose code but you know it's just doing the thing we have selected part over here so when we tap on something and then here specifically we have our our information like hey we've tapped on an item like you know uh we added it apart let's navigate to the add part page pass in the part selected um and then you know deselect it basically and then we also have low data which you know what's nice here is that I'm not putting any HTTP code into my um into my view model right I'm actually putting that in this parts manager that gets called right here so so that way I can reuse that parts manager all over the place which is the ideal scenario here which is nice same thing in the ad part you know we have a part ID part name we have information basically about the part and then what we have is in in um uh some commands to do done save delete so save goes in and all other insert or update so we can create a new one or we can tap on one insert you guessed it goes off and says add and then we have update which creates a a new version of it with their information and then it updates uh calls the update method and then we have delete which calls a delete method so all of this stuff is a sort of standard mvvm the only difference is that we're calling into this parts manager which is pretty nice makes sense I got it cool all right so I'm going to grab that URL that we had earlier that it deployed for us we have four hours left to finish this so that's good and what we're going to do is we're going to go up here and we're going to post in the URL just like that now we have this base URL and then we have this other U url url um and the reason we have that is because like we showed in code you might want to go off and you might want to specifically [Music] um um change that based on different operating systems if you're deploying locally but in this case we're just going to append this base URL onto slash API because if we looked back over here we can note that the default here is slash API Parts on our website because your website might also have your API in it and so we often put API parts so just be aware of like that's what's happening there yeah cool now we are going to want to authenticate ourselves with our back end so that's what we're going to do this get client so instead of trying to authenticate every single time what we could do is actually just maybe store that authentication token once we have it so for authenticated we're good to go and We're Off to the Races so what we're going to do is go into our HTTP client so here we could go off and we could say um if let me pull this over here if client equals null and in fact that should be if client is null okay it is not null okay that's actually better um then we would return the client there we go and then here we just create a new one Visual Studio is just going to fill in everything for us automatically so there's that so uh the next thing we could do is say um I'm gonna do a few things now here's one thing that I think is fascinating we could say if um string uh is null or empty or it could be white space uh if it if it is then we're gonna go need to get an authorization key right now the other thing I would do is I would say um fascinatingly enough we could store it here but we could also store it in our Secure Storage or in our preferences as well because if I stop the application and start the application I'm going to have like a new user so what we could do is we could say you know um the author of the authorization key is there is null we could say VAR um stored key this is like Off Script but I could say preferences Dot and I could say get and then here I could say um auth key and then I could say string dot empty right and then I could say if stored key or if string dot is null or empty stored key then go do this else here in fact you won't even need to do this you could do this right you didn't even get it and then you could check it again say all right is it really right is there really really not in there right um that that way allow us to stop and start the application there's preferences and that's part of Maui Essentials there's also um there's also Secure Storage which is stored in the keychain on the different devices that has different setup requirements that you would need um the defaults here for this this this information you'd mostly Store settings in so I'd mostly store this in Secure Storage but you know for demo purposes we can store it here it is secure by default it's to your application so no one else can access it but regardless we'd have this here and then we could say is we could say authorization key and what we can do is we can say oh wait I'm going to say get a client dot get string async and what I can do is I can pass it in the URL but I can pass in login now here this has a slash on the end I don't really like that necessarily so I'm going to delete that because I think that's bad practice but that's just a me I'm going to go in I'm going to say you know URL which is my default and then slash login I like that because now I know for sure like where it's coming from does that make sense yeah yep now this is going to return back to me some information as well so I'm going to give it an authorization it's going to give us some Json technically I don't think it actually does and it just it just returns a string yeah yeah so we don't need to do anything else I don't think no but I'm going to store it so I'm going to say preferences dot uh set and I'll say auth key and then I'll say authorization key so I only need to call it ever once yup makes sense yeah cool so what's amazing is you went through all of this but a lot of times if you're using a authentic like we're doing an active directory yeah the M cells don't take care of all this stuff for you and it'll save it and it'll get refresh tokens and all that other good stuff exactly when we do it by hand a lot of it is going to look like this that you would have to do to keep it like for other things something not I'm talking authorization keys but there might be other things that you download that you want to keep around like your name like a profile or something like that we might want to keep like this so yeah light mode dark mode different settings things like that you know good to learn as we're going um the other thing that now we're going to do is set those headers so here we're going to say default headers and there's all sorts of stuff in HTTP but we're going to add specifically um authorization is what the back end is going to look for and we're going to add that auth key and that'll be for the entire life cycle of the client so we don't need to add that every time just once and then I'm also going to add another default request header which is ADD and this one will specifically be [Music] um accept and this one is going to be the application slash Json and that's a standardization across all HTTP clients and requests to return specific types of of there's the mime mime and that specifically is going to say what type of data we would like to accept and we don't accept Json back yep yep cool all right now we just need to implement some code basically into our application so let's say we're going to get all the first thing we could do is we could say um here we have some we have um some information here uh that we're going to request from the internet but we're going to check to make sure we have Internet first so here I'm going to say if connectivity Dot and I can say current and I can say network access if it does not equal internet then let's go ahead and just return a new list of parts just empty lists like because it doesn't really matter we're just going to return it back I could do something else there I could specifically do a pop-up I could provide other information we're just going to return that right now yeah um else what we're going to do is save our client equals get client so here it's just gonna we're gonna call get client just to make even though we have a client here that's static so I should probably not make it client I'll say um maybe they call it client I'll say my answer you call a client no scoped that's interesting yeah client so we're just going to get the client right and the reason we're going to call this is only because we're doing this other stuff also I could just create a new one but we're going to do that and we're also going to call a weight on it because it's asynchronous here so that's get client and it's a task and then what we can do is we can say of our result and we can say await and I can say client dot get string async see look the inside here there's get async get string async uh get from Json async uh just get stream async there's also like put async there's a patches so there's a lot of these helper methods in there as well which is nice um but here I can say get string async because I know I'm getting a string so it's going to request stuff and again I'm going to do my URL and then here I'm going to do slash um Parts because that's what I did there boom and then I can say return in this case we're using json.net but we should definitely not use it in the future and just use other stuff there too so the built-in one let's um do get from Json async on the client and then put it the yep oh my gosh yeah and then we could just return on that oh look at that and that should work amazing yeah so that's a helper method built into system text Json so if you've ever used json.net before you need to serialize things out but you don't need to because it's built into.net uh six and seven Now by default which is nice to get these parts out and return from Json wow amazing so cool and the nice part there is that actually if you remove json.net it'll it'll trim down your app size by like half a Meg so that's a fun fact so cool all right so let's just go ahead and run it here on windows so I'm just going to go ahead and debug it and this would work anywhere so let's add some break points here I'm just going to add it across the wire so we can kind of see it come in in real time and then I'm gonna this one's not super important but let's go into our parts view model where we do get all and add a break point here so we see what we're getting back and just go ahead and debug through that papa papa and uh we should get back some default um some default items because if you remember inside of our parts um not the parts of view model but inside of our server there was a bunch of default items that got added into our Factory so it'll return these default parts for everybody Okay cool so on Startup specifically if we look at our um call stack in our load data here this is loading the data on Startup um this is going to go off it's going to call into our controller our manager to get all it's going to say hey I don't have an auth key at all I don't have one here I don't have one here let's go ahead and get one from the internet there we go it's gotten it that's nice I'm then I'm going to store that inside of it oh actually did that I think it actually did returns this now it should be just the is it really returning with the quotation marks it is yeah so we need to do this we need to do the same thing well that's why we deserialized it so get from Json and then I guess it's a string yeah that's weird that is weird good to know good thing we debugged it yeah and didn't store it yet fun fact well that's cool that we can just change that so that's nice yeah I can't wait to update this code that's why we do this live Okay cool so we can write notes and know what's going on yeah or we we run through it but then we improve it really yep so no auth key none from the from there we get it back we view it and now it's just there's no quotes around it oh my goodness okay cool I guess it's because it's returning Json is just returning that back which makes sense that it would yeah so here we're going to do the same thing now we're going to go ahead and grab this from the internet so we're going to go off and grab that here wake the service up should be up why is it well come on this wants to evaluate the expression huh I've also hovered over something I am on the pre I'm on the preview I only installed the previews so let's try it again come on spinning come on Visual Studio oh okay let's go ahead and see what it's doing let's go ahead and crush it and uh try again here is doing something sorry about that I blame myself hot 17.5 preview one stuff happens I am yeah because I was like I don't want to install the other one I'm gonna install the full one so that's me classic James um okay well let's go ahead and just remove this break point I must have I must have been mad at me about something so anyways and let it go ahead and bring in all of its stuff and go ahead and debug luckily it starts up really really fast so it's always good huh you know I've been on on our machine uh and it's beautiful how much faster everything is oh my goodness super good yeah I love it just okay wait wait for that workload to come in yep no so it's kind of cool so um if this works see look at that it actually stored the auth token so it's totally good to go um which is nice and then we don't have to log in anymore and then yeah boom look at this we actually should get our parts back yep we have our parts that are in here which is quite nice and actually we get this new inumeral visualizer you can actually export that to CSV look at that wow amazing yes and that is nice that visualizer you can actually do searches from within it so if you have like a million parts that come back you just want to look at one of them you can totally do that right from that visualizer look at this so here's all of our parts that are inside here if I tap on one it navigates to it over here we have all of our different things so we need to implement that stuff but that's pretty cool right so this is really really nice table view well it's a lot better than I thought it was going to be that's cool um some of you come back in 2022 so there we go there's all of our parts coming in really simple right so hopefully not mind-boggling there let's go ahead and do the other stuff really quick um and put that into our service and then we're going to call off to because all the code is is there for us already we just need to implement it right so let's go in and let's go into our ad over here so again we're just going to go ahead and um we're gonna do the post first so here if I don't have internet I think this should actually return null I don't know what it's doing a new part yeah we'll have to take a look at the code yeah I think it's a return doll yeah that's me else what I'm going to do is I'm going to go ahead and create a new part here we can use the new required things and down at seven that'd be fun um but we're basically going to enter some information about the part name supplier the type here pass it information down and then what we're going to do is we're going to create a new HTTP um request a message and in this case we're going to say please post to this URL okay and then what we're going to do is we're going to set the content so I'm going to say message dot content and say Json content which is part of systemnet HTTP Json dot create I'm going to say part of the part that we just created so it's going to create the Json content for me which is an HTTP content yeah which is nice yep now beyond that all I need to do is send that message so I'm going to say VAR response equals await client send async again Visual Studio writes it for me and then response Dot ensure success status code just like that and then what we can do is we can do this we can actually say um uh VAR item equals a weight I wonder if this does it response dot content Dot read as I guess string async there we go and how do we get the item um once you have the string you have to deserialize it back in the yeah from Json okay but how do we do with the new one system you know what is there on the client a send as oh I see what you're doing oh I guess you could just do here I think you just do VAR inserted part and you could say Json Json content no trying to figure out the new apis yeah there's a way to do it Json there we go there we go Json serializer.com serious realize the Json that comes in there's an extension method that definitely helps with that that is for sure yeah so do me a indulge me here James for just a sec yeah on instead of client.senda sync yep give me some um intellisense here is there a send oh there's just send a sync I was hoping to be like a send as Json async or something like that where it would automatically or serialize our our part into part of the uh there might be an extension method with like a HTTP like a using statement we need to bring in yeah that could be yeah anyways all right well we'll put it in there anyways this does it so anyways it sends it asynchronously it gets the Json content so we're just using new stuff this system that HTTP Json um it's gonna send it async and share this code and then we're gonna read as async boom now let's do the other ones I'm just going to literally copy pasting code because I'm I'm just going to do this so update here we're going to do like literally the same thing so here we're just going to say VAR oh that's interesting uses new a little bit of r oh that's funny either way I'm going to say parts now the difference here is that we're going to do update and we need to give it the part ID so normally how restful Services calls we have the URL the the end point to hit and then pass an additional information in this case we need to pass in an entire part the entire Json blob that will then get deserialized down for this one what we're going to need to do is pass an identifier so if we look specifically at that Parts controller we can see that inside of the get there is one for a part ID that takes in that identifier and same with the put here as well so that's kind of nice so there's the put we're going to go ahead and create that content again so let's just go ahead and do that here Boop that's nice so we have the part that's passed in we're going to go in we're going to get the client again oh yeah actually we need to do get client there too yep yep there's I've somehow missed that in there I think we should call those different things basically in the code but um there's that and then we're gonna return this off and ensure success and it just returns a task so nothing special on there probably return an error code that would be ideal and the last thing we're going to do since we only have so much time is we're just going to go ahead and also implement the delete so boom got the delete we're going to create a message just like this but we're going to put in you know the URL Parts this but pass in the verb get the HTTP client just like that and send it out so surprisingly like these are very similar right so up here the update and delete the only difference is that we're setting the content and then we're also just calling delete now we could have for example just called like a weight client dot oops delete async like that's totally super valuable like we could have just called that I wouldn't I would do the same thing but we like to show that you know there's verbose ways in the shorter ways of doing it it's up to you what you want to do yep all right let's run it and what I want to do is I want to go into my ADD Parts view model so we can kind of see um uh what's happening here so this kind of cool we navigate backwards and we actually send this messaging center thing yeah um but yeah and a lot of times with uh um rust Services you might be wondering why especially on the put like we're sending the whole part anyway why couldn't just put take the part ID out of it why do we have to put it in the URL and the idea behind all breast Services is that you can look at the URL and kind of just tell what's going on yeah like so it's specifically identifying like that first part that zero five whatever so it's a little verbose but that's the idea behind the um the whole rest service um yeah I'm a part name specification and that the URL 100 outlines what you're operating on now here we can see I can't set the part ID because I'm creating a new one so it's disabled because it's going to be created by the database so I'm going to hit save it's going to create that and then it's going to create a new ID so there it is or there's the identifier part right there that it gave me automatically and then we just call the back end I said update and then there is you right there which is cool yeah if I want to change this one here and I want to say um here and I can say save boom this is going to go do it now again I want to make sure that people know this is real it's not just like in memory that we're saving these things I'm going to restart the application here and the nice thing since we're saving the auth token is that we're going to see the same information come back so I'm going to pull over the app scroll down then there's Matt right there there we go I'm going to save it again it's going to go off to the Max and then boom there it is right there and there's also the the two two that we entered we can also delete that part so there it goes it's gone we can delete this here delete Matt that's gone and uh uh you know let's go ahead and just delete some of this stuff and then now if I go in and I you know reboot it again just like this now we've gone off and we have should only have one part basically so I'm gonna drag this heart out and we just have one part right and again we can add we can add map back at code now Matt nice little Twitter call out a little Twitter call out foreign my part types keep on changing yes give my little heart there oh really like that we'll save boom there we go there we are that's really cool so we can automatically get that up and and running 100 and we're totally good to go look at that we just implemented everything from start to finish bounce awesome cool all right let's go ahead and I thought it was going to be a lot shorter today but it's right on time what do you know right on time yeah oh good uh Diego saying in the chat there's put as Json async so that's cool okay um that might be an extension method um interest so let's actually pull that up uh let's go into that because I they're newer ones I always forget them the nice thing yeah yeah because if you don't know what you don't know especially when once you get into the habit of using what you know you don't know what the new ones are oh there it is oh there it is yeah look at that wow why do we have a post as Json async I don't know it's post as Json it says it's there maybe that added an extension property up top that we that I did okay it may have it's possible I'm interested now so this would be a part right and then yeah this would say oh use the URL right and then it should be the value yep which would be the part yeah I don't know if it needs a cancellation token yeah probably not this should just return uh your request our response yeah so then what I'm interested in is oh yeah then you don't even need yeah you could just do this WOW amazing we're going to update this to be even we're gonna make it cooler yeah I think it's good to show both like you can do it like we should we should write it and document it in case people want to do it but this is way nicer and then what you're saying is that we should be able to do post add this one right can we do yeah there's meaning why wouldn't there be one for a post says Json I think oh my gosh and there is so then yeah then you could just do all this wow yeah which totally makes sense at why they put those in there there's a lot of code that you just got rid of there I know that there's an extension to read something as there's a way to do it yeah do it you know I think I do it in um I could do it in uh uh I think I do it in here let me see let me look looking looking ah yeah it's read from read from Json async ooh oh nice I don't know what's going on my screen well the private mode going on now apparently what is happening what is that what is going on um I don't know what's going on you could see your taskbar but the main screen upward that's weird have you ever seen that no never seen that uh-uh that's wild um no idea um interesting okay well that's cool said something with stream yard that does that it's like there's something on his settings I don't think so I I don't even know I have no idea what just happened I'm gonna stop sharing my screen no it's still there nice yeah it is a nice blurb it is a beautiful blur effect I don't know I don't know who's doing it um it's not Visual Studio it's not the PowerPoint are you seeing it blurred on your main screen or is it just yeah really yeah [Music] yeah wow okay um well let me go ahead and bring up the PowerPoint and let's wrap it up and I'll be able to see only one screen that's fine we're done we got five minutes left so that's cool um all right I'm gonna bring this up I can't see it though which is hilarious so maybe don't bring up my monitor until I move it off the screen over here this is hilarious I don't think it's a stream yard thing no that would I mean I thought like streamer was just blurring your screen for us but if you're seeing a third screen I see a blurred screen yeah I have to reboot see what happened okay cool let's recap really quick let me go and put this on my main one here uh nope not that one let's bring it on to my primary monitor all right there we go it'll be a different resolution if you get it so what do we do today we detected if we have internet connectivity we figured out that some some keystroke combination blurred my screen we consumed a rest service we took advantage of native Stacks all sorts of good stuff and we use all sorts of new Json Tech stuff so thanks everyone on the channel that's why we do this live it's so cool um you can find more information by scanning this QR code or you can go to the summary page you can take the learn stuff you can get your points all the stuff um and you did it you totally learned it and hopefully now you can take advantage of rest services and some of these cool new apis and next week we'll be finishing the last episode of our learn live series on building down in my applications I'm storing local data with sqlite and Donna Maui applications now I will not be here for this um I know I I had a conflict with another conference at vs live in Orlando so I'll be down there and I and I will not have a place to present from or try to join in in general so we will have a even better replacement than me so there's there's amazing folks we'll find a guest host for next week that's for sure so this will be the the end one if if I'm able to find a spot I'll try to jump in at the last minute all right and um and just say hello you know what I mean from the conference but yeah thanks everyone for hanging out we're not gonna do the um um continue the conversation today what we're going to do instead is we're going to tell everyone to head over to net comp because it is the biggest.net conference of the Year happens every single year in November with the launch of Donna 7 which just happened yesterday day one was there and day two is going on right now and there's some amazing sessions going on that you need to check out in fact happening in two minutes is the GitHub universe.net conf Crossover with Scott Hanselman I need to go watch that so let's go head over there now thanks everyone tune it in we're not going to go there we're just going to end on that perfect thanks Matt all right thank you James thanks Katie thanks everybody it's been an honor uh to do this for the last six weeks it's been fun foreign
Info
Channel: Microsoft Developer
Views: 9,202
Rating: undefined out of 5
Keywords: microsoft learn live, dotnet, dotnet-maui, vs, developer, student, beginner
Id: MxImRQEWe_w
Channel Id: undefined
Length: 89min 20sec (5360 seconds)
Published: Wed Nov 09 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.