Flutter : Post api implementation with dio | amplifyabhi

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this vlog we would like to deal with the  implementation of post api request if you   have gone through our previous tutorial we have  implemented a network call with the help of a do   library and we have seen all the basic structure  all the basic code implementation so i'm just   making use of the same code and trying to make  a post api call instead of a get api call which   we have done in our previous tutorial so if you  have not gone through our previous tutorial i   will suggest you to go through that particular  tutorial because it will be very much helpful   for you to understand this particular tutorial  and here in the postman when we try to observe   an api call here so we we are trying to make a get  api call and when you tap on the send button here   you will be observing a 200 okay as a status code  so this is the standard response for http request   which states that our api call is success and  also there are different ids for different api   requests for example if we are trying to make  a get api call then 200 okay will be appeared   in our status code here if you try to observe  the output when we try to make a fetch api call   here we are even getting this particular status  code in our code when we try to print the status   code we are getting 200 here and below which we  are getting the response for our gate api call   so quickly get started with our post api  implementation and we'll try to see what   are the steps to be taken for implementation  of the post api call so let's get started so the very first thing we need to do is like  we need to implement post here instead of get so   let's create a variable response equal to await to dot we are having here various api request  implementations like we are having get which   we have done in our previous tutorial and now i am  using post here so you can just make use of a post   or post uri both the things will handle the post  api request here so i have added post here just as   to cover the basic implementation if you want to  add post url then there is nothing much difference   just the way you specify the path and  now let us try to specify the path here   so the very important thing is like the apis  are categorized like for get api to perform   a get api request so this is the url here and for  making a post api request here we need to add post   we need to append the url with post here so  don't get confused here again these are the   creation of apis which we are not concerned  according to this particular tutorial this   is the api which we are making use to test  our post api request we have provided the   first parameter that is the url and now we can  just consider removing the get api request here   add a comma here and try to specify the  parameters which you are trying to post so   add the parameters with the help of the data key  here and specify them within the curly braces here   in terms of key value pair so the very first  thing i would like to consider is name here   specify name here so i'm just specifying my name  and if you want to add one more parameter here   if you want to post one more parameter so  basically consider this is like you are trying   to submit a form and save the details into your  database so i'm just specifying name and email   as two different fields in the form  and let us specify the data accordingly   and again here we have manually provided the data  but what i suggest you to try is whenever you are   trying to create or try to make use of this  particular tutorial then try to add two input   text fields to your flatter application and try  to fetch the data from those input form fields   and try to append the data in this particular  key value page here and try to submit it so that   it will be very much helpful for you when you are  trying to implement in a real time implementation   according to the implementation for post  api call we have successfully done it and   now before trying to implement this particular  post api call once try to test it in the postman   so let's try to copy this particular url and try  to paste it over here and try to make a post api   call for this particular url and yes this is a url  for get api call and try to see whether this works   so here we can see we are clearly seeing a  404 status code so 404 is like for not form   so whenever you are trying to see the status  scores here you are also trying to see a message   to the right hand side of them so it's 200 it's  saying like okay so the api call is successful and   when the api call fails here it is also showing  the reason like not found the requested resources   could not be found because this is the url which  is being used for get api request and not for the   post api request so what we need to do instead  of to do's here let's try to add ports here   and if you try to tap on send button now then  yes this particular url will work for sure   because we have not added any validations  in this particular api creation   so it will automatically create some  data for you like empty data it will be   creating let's try to add our parameters  here what we have considered it's like   name and email now so let's go to the  form data here and try to add a name here and in the second field let's try to add a email  as key and value as we at the rate mail dot com so   let's try to copy this particular url here and try  to make a get apa request for this particular url   and here you can observe user id is one and id is  also one but here if you scroll down a bit and try   to observe the id here id is incrementing like 2  3 4 and when you scroll down completely here the   last value is 100 here and now let's try to make  the api call and i will try to explain you why we   have made a get api request so here we have made  an api call and we have got id 101 return so what   is this id 101 return we have specified a name  email here as a parameter to our post api call   and we have got id 101 and also what is the status  code here 201 we have got and it is saying created   so just carefully observe here the first time we  make a get api request we have got 200 okay and   when we try to make use of the same get api url  for post we have got four not for not form and now   we when we try to make a successful post api  call then we are getting 201 created so here   201 is the status code whenever you try to make a  post api request and the message it is saying is   like created so what it is created so the name and  email id are been added to our database so we have   created a resource okay but when you try to make  a get api request you will be not you will not be   getting this particular data name and email here  because we are just using a third party free tool   here so this particular api is just for testing  and it won't be saving all the data when you are   posting it but i am sure this is the same scenario  when you try to implement the post api call   and in your real-time apis as it will store the  data so whenever you try to make a getty api call   that will be added to the existing list okay  so there is no doubt here i am hundred percent   confident because this is just a free tool it  won't be storing all the data which you try to   post here okay so that is why we are not getting  uh uh when we try to make a get api call here   so this is how we can make the post api call here  and now let's get back to our code and try to   test our code which we have written so instead of  fetch data i would like to add here is like post   data and try to run this particular code so now  let's try to tap on this particular button here   and observe the output now so here we have got the  same output like flutter 201 so what is the 201 is   the same status code so here 201 is the status  code which we have observed in the postman here   and also the response is one not one we have  got and here you can see in our code we can   clearly see our resources being created  like it is providing the name email id and   also the id it has allotted for it  in postman we are not able to see it   but the same response we are trying to see in our  code level so i think you are now got a confidence   like our post api call is successfully implemented  and we have even got the response here and one   more thing i would like to specify you here like  why is this response in this way but at the time   of api creation the developers will try to provide  what are all the required fields in the response   so we need not get the name email or whatever the  things we pass in our post parameters but they   will consider what are the things to be returned  to the user so that they can understand that the   api call is made successful because if you try  to pass a password here you might think like   the password will also be coming in the response  no it's not the thing so they will customize the   response and try to send you so that you can  understand that the resource is being created   that is the post api call has been implemented  successfully so this is it for this tutorial on   the post api implementation and if you are having  any queries do let me know in the comment section   below and i would like to provide you the code  in the description section below so if you like   this tutorial do like share and subscribe to our  channel for more interesting content on flutter you
Info
Channel: amplifyabhi coding
Views: 7,297
Rating: undefined out of 5
Keywords:
Id: Gj_z_9PvN9U
Channel Id: undefined
Length: 11min 53sec (713 seconds)
Published: Thu Sep 08 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.