Improve App With Best Practices

Spring Boot: Build Your Website Real Quick Micro-Service With Spring Boot
11 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$99.99
List Price:  $139.99
You save:  $40
€92.78
List Price:  €129.90
You save:  €37.11
£79.40
List Price:  £111.16
You save:  £31.76
CA$136.11
List Price:  CA$190.56
You save:  CA$54.44
A$154.13
List Price:  A$215.78
You save:  A$61.65
S$135.08
List Price:  S$189.12
You save:  S$54.03
HK$782.28
List Price:  HK$1,095.23
You save:  HK$312.94
CHF 90.61
List Price:  CHF 126.85
You save:  CHF 36.24
NOK kr1,085.23
List Price:  NOK kr1,519.37
You save:  NOK kr434.13
DKK kr692.01
List Price:  DKK kr968.84
You save:  DKK kr276.83
NZ$167.80
List Price:  NZ$234.94
You save:  NZ$67.13
د.إ367.19
List Price:  د.إ514.08
You save:  د.إ146.89
৳10,976.08
List Price:  ৳15,366.96
You save:  ৳4,390.87
₹8,339.52
List Price:  ₹11,675.66
You save:  ₹3,336.14
RM473.25
List Price:  RM662.57
You save:  RM189.32
₦141,842.81
List Price:  ₦198,585.61
You save:  ₦56,742.80
₨27,810.04
List Price:  ₨38,935.18
You save:  ₨11,125.13
฿3,647.70
List Price:  ฿5,106.92
You save:  ฿1,459.22
₺3,232.12
List Price:  ₺4,525.11
You save:  ₺1,292.98
B$499.21
List Price:  B$698.91
You save:  B$199.70
R1,908.54
List Price:  R2,672.04
You save:  R763.49
Лв180.65
List Price:  Лв252.92
You save:  Лв72.26
₩135,197.71
List Price:  ₩189,282.20
You save:  ₩54,084.49
₪368.63
List Price:  ₪516.10
You save:  ₪147.47
₱5,633.91
List Price:  ₱7,887.71
You save:  ₱2,253.79
¥15,144.47
List Price:  ¥21,202.86
You save:  ¥6,058.39
MX$1,659.40
List Price:  MX$2,323.22
You save:  MX$663.82
QR364.31
List Price:  QR510.04
You save:  QR145.73
P1,370.91
List Price:  P1,919.33
You save:  P548.42
KSh13,148.68
List Price:  KSh18,408.68
You save:  KSh5,260
E£4,729.52
List Price:  E£6,621.52
You save:  E£1,892
ብር5,680.63
List Price:  ብር7,953.11
You save:  ብር2,272.48
Kz83,612.74
List Price:  Kz117,061.18
You save:  Kz33,448.44
CLP$97,978.20
List Price:  CLP$137,173.40
You save:  CLP$39,195.20
CN¥722.95
List Price:  CN¥1,012.16
You save:  CN¥289.21
RD$5,921.50
List Price:  RD$8,290.34
You save:  RD$2,368.83
DA13,490.83
List Price:  DA18,887.70
You save:  DA5,396.87
FJ$226.12
List Price:  FJ$316.58
You save:  FJ$90.46
Q779.86
List Price:  Q1,091.83
You save:  Q311.97
GY$20,923.51
List Price:  GY$29,293.76
You save:  GY$8,370.24
ISK kr13,946.60
List Price:  ISK kr19,525.80
You save:  ISK kr5,579.20
DH1,013.19
List Price:  DH1,418.51
You save:  DH405.32
L1,763.34
List Price:  L2,468.75
You save:  L705.40
ден5,702.11
List Price:  ден7,983.18
You save:  ден2,281.07
MOP$805.89
List Price:  MOP$1,128.28
You save:  MOP$322.39
N$1,893.44
List Price:  N$2,650.90
You save:  N$757.45
C$3,681.15
List Price:  C$5,153.75
You save:  C$1,472.60
रु13,335.63
List Price:  रु18,670.42
You save:  रु5,334.78
S/370.84
List Price:  S/519.19
You save:  S/148.35
K382.72
List Price:  K535.82
You save:  K153.10
SAR375
List Price:  SAR525.01
You save:  SAR150.01
ZK2,522.76
List Price:  ZK3,531.96
You save:  ZK1,009.20
L461.43
List Price:  L646.02
You save:  L184.59
Kč2,350.75
List Price:  Kč3,291.15
You save:  Kč940.39
Ft36,729.02
List Price:  Ft51,422.10
You save:  Ft14,693.08
SEK kr1,071.30
List Price:  SEK kr1,499.86
You save:  SEK kr428.56
ARS$85,766.82
List Price:  ARS$120,076.98
You save:  ARS$34,310.16
Bs691.04
List Price:  Bs967.48
You save:  Bs276.44
COP$387,583.68
List Price:  COP$542,632.66
You save:  COP$155,048.97
₡50,832.34
List Price:  ₡71,167.31
You save:  ₡20,334.97
L2,468.78
List Price:  L3,456.40
You save:  L987.61
₲737,805.73
List Price:  ₲1,032,957.54
You save:  ₲295,151.80
$U3,781.90
List Price:  $U5,294.82
You save:  $U1,512.91
zł400.73
List Price:  zł561.05
You save:  zł160.31
Already have an account? Log In

Transcript

Hey there welcome back friends. In this video we will talk about our application and a couple of issues which are associated with our existing application. So as of now if I click on this link, it is loading up this list, take note of it, this is a list this is not a JSON response proper. This is a list which has JSON responses, this type of response is not recommended. While it is not recommended is something which we will discuss in some time. Let me minimize this.

If I show you the app of our app, we are making use of rest template. Now rest template is one of the way using which we can communicate with microservices. Now there is yet another way to communicate with micro services. And that way is definitely web client. web client will enable you to code asynchronous program and that falls under asynchronous, pardon me that falls under reactive programming. Now, as of now, we won't worry about asynchronous or reactive programming we will go with synchronous approach, but there is something known as asynchronous which Spring Boot supports.

So, take a note of it all right Apart from that, we are making use of rest template, which is cool, but in here we are making use of this a string class, we are not like converting the response into a proper object, we will also do that that is a way to go. And finally, we are displaying information on our page, which is nice, but the issue lies into this response. This response is nothing but a list. So, first of all, let us convert this as an object. All right, so, let me open up the Samsung app. And here we have the device list.

Oops, I have made a mistake in here. Let me rename the package. defector Do you name it should be model I have made this mistake let me fix this. And inside this model we will create a yet another package pardon me create another class by the name of devices and it would be a list of device. Here we go. Now friends you might be thinking that why we are like creating this class where we are making use of this list and then using the object of this this devices now hold that thought in your mind for some time I will discuss that in brief in some time as of now let us quickly complete this we will give the name as devices.

Here we go. And now let us quickly do what that let us quickly add a constructor it's parametrized Let's add getter and setter. And finally, let us also add the to string method shipibo Let me save the changes alright. And we need to also add the required import. All right. So this this looks good to me, this is nice and now we will make use of the object of devices type.

So again, let us navigate to our app Samsung dot java. And that this this particular method will now return an object of devices type. Typical and here, it won't be a list it would be definitely object of devices type. So it would be like First of all, we will need a list by the name of devices. And here it would be like devices devices led List equals new devices and to this devices we will pass on this list devices. Now, finally, let me also bring this line after the list creation.

Now usually, when it comes to these three lines creation of this list of devices, it would be what it would be usually a database call and we will receive the information from the database and we will then create an object no plans to why we are doing it like this. Now, imagine, whenever we are making use of a list as a return type. For a RESTful API, it is not a good practice because it will remove the flexibility. When it comes to list and list can contain only one type of data a list can be off only one type of data. Whereas whereas insert object we can add any type of property. In here, we are dealing with a list.

But later down the line, for example, we want to add some additional property, we can do that. It's very simple, it is very easy, right? As a result, it is always convenient to add objects rather than list that will be a better practice. Alright, friends later down the line, I will also show you a real life API a real life small little project. And you will able to see that even in the industry, people will never use a list even though they can. Alright, now let us rerun this application real quick.

Here we go. And now if I refresh this page, things will change. Right? So you can easily make out that here we have object devices. And inside the devices, we have a object and this object is of type list, right? And that could be more things inside This object for example, for example, later down the line, I plan to add a yet another property inside this this particular class then it would be very simple for example, a string brand name equals Samsung.

Pretty standard stuff, let me quickly add in the getter and the setter for the same. Let me quickly get rid of the to string method and add a new to string method. All right, so we are all set. And now let us rerun this application. Here we go. And now for example, I refresh this page and click on Samsung, then you would be able to see that there is this yet another field by the name of Samsung, right so we have this list.

Apart from that, we also have this brand name Samsung. So when it comes to working with object, it is very convenient, and your application will be skewed liberal there won't be any hurdle when you wish to scale your web service. So, here is the important thing All right. Now moving forward, let us check our application here. The next thing the next thing here we are getting the information which is cool, but we are not converting the object into a proper object we wish to convert it properly. So what we will do, we will simply create a jet another model.

So, here, we don't have a model package. Let us quickly do that. So, here we'll create a new package by the name OSS model. Good enough. And inside this model, we will add two classes. And these classes could be device and devices class.

In fact, we do have these two classes. Can we copy and paste it in here? Will it be okay yes, we can do it and We will definitely make some changes in here, let me get rid of the package and click on this option and add the package declaration good enough that will do the same for devices. Let me get rid of this statement ask Eclipse To add a new statement alright. So, this this looks good. And these these two are what these two are nothing but models which we have simply copied no rocket science.

And now, let us quickly check our application here. Here what we will do we will simply make use of devices devices class like this, this is cool and people receive the devices only. So it would be like devices result All right. So this is good. And now finally, let us refresh the speech. Let me also rerun this application that would be good.

All right, so ideally what happens is we need to create the models based on the structure of the response, which we receive, but in here we have taken a shortcut and we have simply copied and paste the device and devices dot java file from our Samsung project. So small little shortcut which I have added how I have copied I have selected these two files, right click copy and highlight the package and paste it and you will get the files in here. All right, so this is nice. And now again, let us open up our store. application. Let me click on Samsung, and we get output.

This is nice. This is good. All right. So we have also like, converted stuff. Now once we have once we have this information in the view file in the view file, we are simply displaying the object, but we can likely deal with things we can extract information, and we can display information in a proper manner, which we will do. But before ending this video, your homework, your homework is to create a application similar to Samsung.

And when the user clicks on this link, Apple link, it should list list. Devices list similar to this. Alright, so take note of it. The name of the devices must be little different. For example, it could be like iPhone eight, or iPad new or something like that, and it displays information. So take note of it.

Try to create a new application try to create a application based on Apple devices and then we'll move forward from a one next video. Alright, so here we go. The only thing which is left is hard coding hard coding the URL, which we will discuss in our next video. Alright, so thanks for watching. Have a nice day and take care

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.