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
€96.21
List Price:  €134.70
You save:  €38.49
£79.93
List Price:  £111.90
You save:  £31.97
CA$143.79
List Price:  CA$201.32
You save:  CA$57.52
A$160.48
List Price:  A$224.69
You save:  A$64.20
S$135.83
List Price:  S$190.17
You save:  S$54.33
HK$777.07
List Price:  HK$1,087.93
You save:  HK$310.86
CHF 89.45
List Price:  CHF 125.24
You save:  CHF 35.78
NOK kr1,141.95
List Price:  NOK kr1,598.78
You save:  NOK kr456.82
DKK kr717.64
List Price:  DKK kr1,004.72
You save:  DKK kr287.08
NZ$177.52
List Price:  NZ$248.53
You save:  NZ$71.01
د.إ367.25
List Price:  د.إ514.17
You save:  د.إ146.91
৳11,994.74
List Price:  ৳16,793.12
You save:  ৳4,798.37
₹8,496.63
List Price:  ₹11,895.62
You save:  ₹3,398.99
RM450.75
List Price:  RM631.07
You save:  RM180.32
₦155,628.43
List Price:  ₦217,886.03
You save:  ₦62,257.60
₨27,934.96
List Price:  ₨39,110.06
You save:  ₨11,175.10
฿3,444.45
List Price:  ฿4,822.37
You save:  ฿1,377.92
₺3,518.54
List Price:  ₺4,926.10
You save:  ₺1,407.55
B$617.53
List Price:  B$864.57
You save:  B$247.04
R1,837.80
List Price:  R2,572.99
You save:  R735.19
Лв188.31
List Price:  Лв263.64
You save:  Лв75.33
₩144,872.25
List Price:  ₩202,826.95
You save:  ₩57,954.69
₪364.89
List Price:  ₪510.86
You save:  ₪145.97
₱5,883.01
List Price:  ₱8,236.45
You save:  ₱2,353.44
¥15,672.80
List Price:  ¥21,942.55
You save:  ¥6,269.75
MX$2,028.91
List Price:  MX$2,840.56
You save:  MX$811.64
QR366.34
List Price:  QR512.89
You save:  QR146.55
P1,382.59
List Price:  P1,935.69
You save:  P553.09
KSh12,923.70
List Price:  KSh18,093.70
You save:  KSh5,170
E£5,091.27
List Price:  E£7,127.98
You save:  E£2,036.71
ብር12,764.56
List Price:  ብር17,870.89
You save:  ብር5,106.33
Kz91,790.82
List Price:  Kz128,510.82
You save:  Kz36,720
CLP$99,155.08
List Price:  CLP$138,821.08
You save:  CLP$39,666
CN¥729.81
List Price:  CN¥1,021.77
You save:  CN¥291.95
RD$6,104.52
List Price:  RD$8,546.58
You save:  RD$2,442.05
DA13,454.60
List Price:  DA18,836.98
You save:  DA5,382.37
FJ$232.11
List Price:  FJ$324.96
You save:  FJ$92.85
Q773.21
List Price:  Q1,082.52
You save:  Q309.31
GY$21,000.46
List Price:  GY$29,401.48
You save:  GY$8,401.02
ISK kr13,903.60
List Price:  ISK kr19,465.60
You save:  ISK kr5,562
DH1,007.40
List Price:  DH1,410.40
You save:  DH403
L1,841.78
List Price:  L2,578.57
You save:  L736.78
ден5,922.50
List Price:  ден8,291.74
You save:  ден2,369.23
MOP$803.42
List Price:  MOP$1,124.82
You save:  MOP$321.40
N$1,834.70
List Price:  N$2,568.66
You save:  N$733.95
C$3,694.32
List Price:  C$5,172.20
You save:  C$1,477.87
रु13,665.58
List Price:  रु19,132.35
You save:  रु5,466.77
S/374.71
List Price:  S/524.60
You save:  S/149.89
K406.86
List Price:  K569.63
You save:  K162.76
SAR375.72
List Price:  SAR526.02
You save:  SAR150.30
ZK2,777.96
List Price:  ZK3,889.25
You save:  ZK1,111.29
L478.81
List Price:  L670.35
You save:  L191.54
Kč2,418.25
List Price:  Kč3,385.65
You save:  Kč967.40
Ft39,800.47
List Price:  Ft55,722.25
You save:  Ft15,921.78
SEK kr1,103.66
List Price:  SEK kr1,545.17
You save:  SEK kr441.50
ARS$102,190.76
List Price:  ARS$143,071.15
You save:  ARS$40,880.39
Bs693.61
List Price:  Bs971.08
You save:  Bs277.47
COP$437,799.12
List Price:  COP$612,936.28
You save:  COP$175,137.16
₡50,480.33
List Price:  ₡70,674.48
You save:  ₡20,194.15
L2,548.03
List Price:  L3,567.35
You save:  L1,019.31
₲784,126.06
List Price:  ₲1,097,807.85
You save:  ₲313,681.79
$U4,460.41
List Price:  $U6,244.75
You save:  $U1,784.34
zł409.96
List Price:  zł573.96
You save:  zł164
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.