Spring Boot Fundamentals: Building and Consuming REST Based Web Services | ChargeAhead LLC | Skillshare

Playback Speed

  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Spring Boot Fundamentals: Building and Consuming REST Based Web Services

teacher avatar ChargeAhead LLC, Technologist

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

10 Lessons (31m)
    • 1. Course Overview

    • 2. Roadmap

    • 3. Audience

    • 4. Prerequisites

    • 5. Tools

    • 6. Demo: Creating Model, Repository and Service layers

    • 7. Demo: Linking Database

    • 8. Demo: Creating REST endpoints

    • 9. Demo: Consuming REST Services

    • 10. Summary

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.





About This Class

In thisĀ course we will demonstrate how Spring Boot makes it easy to create and consume REST services. We will create CRUD REST endpoints for the items in our inventory. We will then see how to consume REST APIs in our Spring Boot project. We will take the web layer of our spring MVC app we built earlier and instead of fetching data from a database, we will display the front-end, consuming data from the REST APIs

Meet Your Teacher

Teacher Profile Image

ChargeAhead LLC



Class Ratings

Expectations Met?
  • Exceeded!
  • Yes
  • Somewhat
  • Not really
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.


1. Course Overview: arrest based Web services are the backbone off a rocket picture. These epi eyes are very popular and used extensively for building loosely coupled modern Web applications. Hello, my name is Bunker Jane and welcome to this course on Springboard Fundamentals building and consuming, arrest based Web services. In this, Gore's well first start off talking about Horwood right audience for the scores. Tools needed to follow along and Prerequisite were most successful with scores. Level demonstrate. Hot Spring Boot makes it easy to create and consume arrest based Web services. We will create crowd dressed endpoints for the items in our in wintry. We will then see how to consume arrest AP eyes in our springboard product. We will take the Web layer off of our spring embassy app we built earlier in the course springboard fundamentals connecting to a database. And instead of fetching data from our database, we will display the front end consuming data from the rest FBI's. There should be a fun course, so that's get started 2. Roadmap: I plan to create a series of courses covering the various aspects Offspring boot and wanted to take a moment to go where the courts roadmap to let him know what is coming and what we will cover in each course. The full scores, springboard fundamentals, basics and getting started. We will introduce spring boot, cover its fundamental concepts, and we'll get started developing applications. We will see how to use spring initialize er rapidly build and run a simple Weber first and then a console application in the next course spring. Good fundamentals Creating a spring embassy app will build a fully functional spring, NBC App for Managing Item Elementary. We will implement the model service controller and view layers to show the items in wintry really use timely for the view layer. We will explain how to integrate third body libraries like Jake Witty, bootstrap, acceptable in our application and refer good model attributes in the view Earlier will also introduce Springboard Death Tools, which makes development investing easy in the next course springboard fundamentals. Connecting to read a base will continue building over AB and corrected toe a back end database using Springer the GP repositories. We'll start with anonymity, database H two and then later switched to my sequel to show how springboard makes it easy to work with religious databases and switch them at ease will create the ad update, delete operations and complete our spring Embassy AB. Creating timely views for adding in the leading along the way will further explore time. Leave template engine In the next course. Springboard fundamentals. Building and consuming arrest based Web services will demonstrate how spring boot makes it easy to create and consume rest services. We will create great dressed endpoints for the items in that invent tree. We'll then see how to consume rest FBI's In our springboard project. We will take the Web layer off our spring remesy app built earlier, and it sort of fetching data from Madrid. Abi's will display the front end consume later from the rest FBI's In the next course Springboard fundamentals. Monitoring health and metrics with actuators will demonstrate springboard actuators. Detroit is a lot of useful health endpoints and metrics right out of the box with zero according, we will show how to expose and enable the health endpoints. We'll see how to implement our own custom health checks and create new endpoints in the course Springboard fundamentals. Improving performance by implementing cashing, we will demonstrate the cashing support. Springboard provides with just a dependency and a few annotations who can be wise and effective cashing strategy for the application. We will first demonstrate the cashing with the fourth cash manager Springwood provides, and the later sparked the provider to read this in the course Springboard fundamentals. Implementing security. We'll see how springboard makes it easy to implement security. Well first demonstrated basic authentication. Well, then switch over App to use Didem is authentication. Springboard actuator Security is now integrated with the main apse security. We'll see how to predict actuator endpoints. We want to talk about the or to support in the course spring. Good fundamentals are configuration with profiles and deployment. Using docker, we will see how to configure or app for different environments like Devon Prawer using spring for files. We'll also see Holder Doc arise our application docker containers provide consistent development, build test and production environments and make running and deploying our APS very easy. I would recommend taking these courses in order, but if your family, with a certain aspect of string boot. You must skip that course and more to the next one. Further, if you just want to take the course for a certain aspect, it should be self sufficient to explain the concept without necessarily having to take the previous ones, though I will always recommend great the previous courses for a better understanding. So following these cities, of course, is you would have a solid conceptual, and it's turning off. The various aspects of this framework rapidly start developing applications and micro services. All right, let's not talk about the audience for the scores. 3. Audience: This course would be useful for Java and spring developers who want to understand spring boot and also for sort for architects who want to understand this powerful free work and how they should apply to their applications. What are the prerequisites to be most successful with scores? 4. Prerequisites: there are not a whole lot of produces its for the scores. The only thing you need is some basic Java knowledge and some basic spring concepts. Even if you do not have a lot of family already with these, don't worry. I will try to explain the concepts along the way, and you should be able to follow along without much difficulty. Let's next talk about the tools you will need to follow this course. 5. Tools: we will have a lot of demos in the scores as a believe that is the best way to learn the tools I would using. The scores are off course. Jama. I would be using open Judy Kay Warren, 11 but you can feel free to use Java or open Judy Kaye versions eight or above on. Most of examples should work for the i. D. E. I would be using Sprinkle Sweet, which is a flavor of eclipse but is highly customized and optimized for spring development . I would be using the version for it is open source and free and comes with a lot of bells and whistles. But I think you would like, however, if your family with and we like to use some other I d like intelligent etcetera, please feel free to do so. We will use spring boot version 2.1 point four for the databases. We will be using my sequel version, 8.0 point 15 You can find the cold for the demos in the scores and the falling Go WRL 6. Demo: Creating Model, Repository and Service layers: in this demo, it will create a new spring boot starter project. Create the model repository and service layers. Let's create a new project. My going to file new other spring boot spring started a project. Let's Nimet Spring wrist Keep the Builders may even packaging his Jar Java version of 11. Let's keep the rest of the defaults for the artifact and the version I d. Click next. Let's search for Web and added G P A and it. Lastly, let's add, they have tools. Click finish. Now here's our project with the familiar maven structure. Here is the bomb file will see our dependency for GP. A very end of tools. The springboard starter of dependency will make spring boot to most of the spring embassy configuration for us. His of her main class. Will we see the ad, Spring boot application and audition? All right, let's start by adding the morning layered war app to have a clean separation, let me create a model package first. So right click on the main package nor Jews New package. I'm creating it as Conrad example or Democrat model. I want to keep my main class, the one which has the Art Springwood application notation in the base package and then create some packages and red to keep the other layers. All right now, right, click on the package and choose new class. Call it items that's market with the art entity notation to indicate the spring that this is a GOP entity. Our items would have feels integer. Item i d. String item Name. Double latam Prize. An integer adam quantity that is right. Click and choose source. Generate getters and sitter's Next click and choose source. Generate constructor using fields. Let us also add a new ours constructor going to give the primary key that is Marc the other money field with the ad idea. In addition, for the primary key generation, let us use the generated value in addition, but strategy as generation type and value as an entity to indicate to the partisans breuder that it must assign primary keys for the entity using a database Identity column. Let's fix the imports. Let's have our class implement surreal. A civil imported out of the deformed serial virgin. New I d. Next, let's move on to create a depository in the face forced. Let's create a package for it by right clicking and choosing new package. Cornet, comrade Example or Dimona repository, right Click and choose New in the face. Call it items repository interface. Mark it as a depository with the at Repository. In addition, for spring scanning, that is, make it extend Credit Repository, which takes in the object name and its primary key type. So items and interviewed in our case fix the imports. There's always need for the crowd operations to begin. Rigid isn't a phase. Removes the need to read Bala Plate core for crude operations. Next, let's have this service package by right clicking and choosing new package and put it under comrade Example your demo. Now, right. Click on this package and choose new class and call it item service. The service class will be called from the controller. Let's market with the arc service and petition imported. Now order Wire the items repository in the face as variable. I'd, er let's create a met her to get a single atom first So our meta returns An optional item takes in an item mighty parameter and returns I'd, er find by i d taking in the item I d fixed the imports. Next, let's get all the items. Let's create a method which isn't on the list of items. Call it. Get all inside it. We call I tr don't find all Let's fix the imports Jews Jabara Little list. Let's fix the error uproar in casting. Next. That is crude, a method for uncertain update, which will return the item created or updated. It takes in the new item to create or an existing item to be updated. And then we will call return idea and not save with stakes in the item and will have really active if it exists or else inserted. Let's create a delete mentor to complete our crowd operations. It takes in the item to delete, and then we call idea or the lead with stakes in the item to delete Easy, isn't it to create the current implementations? Finally, tell us, Call on delete all matter which will simply call I tr don't delete all So, as you can see, the repository in the face takes care of all the boilerplate code Androids as the crowd methods. Next, let's see how we can link over application with the database in the back end 7. Demo: Linking Database: in this demo link over app to remind secret of the base in the back and and Spring Boat Mexico. Simple will are a few properties in our application or properties file at a dependency for my sequel in our Palm file and spring boot will order configure everything, and we'll have a data source for us. We will configure connection pooling using Hickory CB, and also have started Sequels for us to insert some initial data in our tables. All right, so let's get to it. Let me go to the application or properties file and specify the bicycle properties using spring ordered a source or driver having class name. Specify the my sickle driver specified this print or read a source of u R L as GBC cool on my sequel. Colon slash slash local host 33 or six slash the demo database. Question mark and specify the server time zone as UTC Finally, let me specify the user name and password. Now we can clear the table on our own and insert initial Design it if you need to. That would be the approach I would take for a production database, but for our demo purposes, we can have spring boot clear the table for us and optionally. We can also provide a script for it to insert it on the table for us. So let me add splendor. GP A Don't hibernate dot deals hyphen auto and give it a value. Create, happen, drop really create the tables upon, start up and drop the tables. When the session factory is closed explicitly to believe in the application is stopped to aid and seeing what's going on there is also add a few more properties so spring nor GOP a not show happen. Sequel Equals True will show the Sequels being executed by Hammer Need. Springer GOP ATER Properties DOn't hibernate, not format on discourse Equally good, True Will form under sequel for us and longer level. Don't or don't have a Nader type people to trace. We'll turn on the logging for having any type of trace. Springboard to uses a Curry cp for connection pooling. Let me pace a few properties to configure connection, pulling like the maximum pull size a little time out, etcetera. Now insert some initial data. Let us create a file under swordsman resources and name it as important sequel when Springboard sees a file with this name. And if the spring georgie ph dot hibernate dot de deal happen, always said to create or create drop, it was great. The tables And also excuse this file. Inside this file, I have a couple of simple inserts to our table. Finally, let's go to the prom file and let the pace in the dependency for my sequel. Then right, click the project just maybe in and then update product. Now let's start our product from the console. You can see happening out port drop table if it exists, and then the table. Create statement based on the back end database, and then it runs over script and inserts the data. Not approve Things worked fine. There is verify that Delivered inserted in the mind sequel database here I have my school running. Let me log in as Deb user, use the demo database and then issued Equity Select Star from items and head to see what tour was in surgery. So great our app was able to wire itself up with the my single database and insert data into it. Now let's move on to creating arrest endpoints for our app 8. Demo: Creating REST endpoints: in this demo, we will create the rest endpoints for the current operations to our items table, then really use a browser extension toe. Firefox call breast reclined to make these FBI calls and test that everything is working fine. Now on to our controller layer. That's right. Click on the mean project and choose new package. Call it comrade example or Democrat controller. Now let's create a new class by right clicking on the package and choosing new class. Call it items controller. Let us put the controller on tradition, and there also important the response body an audition, which will make spring convert its return value and Roger to the issue. To be response automatically, you could have simply put the rest controller. In addition, in here, rest controller is a combination off controller in addition and responsibility. In addition, let's make a request mapping with the route mapping off slash AP I. Next, let's order wire the item service. Let's start, but you're finding a good mapping. Get mapping the shortcut for at request mapping method. It'll do request matter, not get using value. You can map it to one or more you oral fragments, so insert curly braces you can put multiple. You are ALS common separate er. We should map to dis mentored here. We'll just map it to flash items. The method would have done a list of items they get. All May 3rd will retrieve the list of items were calling the items service. Don't get all method that is pretty system mark message for the number of items retrieved, Fix the imports and returned the items. Next, let's create a matter for getting a single item. The method returns the items and takes in the path variable i d. And maps it to the integrity parameter than inside. It calls the items service not get mattered, which takes in the i. D. And it does the optional item. The purpose of the optional class is to prototype little solution for presenting optional values instead of null references and sort of or just to put into many of these null checks and avoid no point, no exceptions. We then, er done the item by calling. I don't get let us now create a rest endpoint for inserting an item again, we will use a shorted. In addition, post mapping, which is at request mapping with method request matter, not post it takes in the Ural Patton slash items inside it returns the items in the air. It matter which digs that a quest body and maps it to the item we call the item service Start up. Great. Mattered to save the item in our database I'm reading the item is a similar logic where we will use the port mapping the items service Don't abatement hurt Philip date or in certain item if it is not found Finally to computer credit endpoints. Let's define the delete mapping slash items We met her delete Heard of the string takes in the quest parameter with value i d. Which maps to integrity. I wanted to show you the readers ways off passing parameters using part variables or request parameters. You can feel free to choose whatever style you like inside you First get the item and then call items service for the lead passing in the item A calling. I don't get We're gonna message the item. I t was diligent successfully, but this hour turn implementation is over. Oh, we for what? Important to get mapping for our single get method. It would be good mapping for slash items, slash idea and curly braces. We're passing the item I d as a part parameter protest. These you can use any Tuller brother extension like postmen ex cetera. Here, I'm on Firefox. I'm going to use the restroom extension to get it. You click on the Hamburger Aiken Juice add ons. Search for rest Erred. Click on it. And then after Firefox, Jews are now we see this I can. For the rest of extension. Let's click it. It opens the Alan hitting the drop down. You can choose the issue. Documentary. Want to call? Let's just or E P Eyes First, let's call the issue DP Local host a deity slash FBI slash items to get all items and we see her list of items returned in the Jason format. Let's call the FBI to get a single item. So after the path, the item i d. Let's say two and a single atom French FBI is working just fine. Now let's are a new item. So change the method to post to the header that has add content type as application slashed his own in their quest. Barney, that is, choose custom that based the dis on here. I do not need to specify the item i d as it will be generated. Modify the u R L to remove slash to let me hit send request and with your new item with I d created. Now if you go to the history, click the get forgetting all items and hits and request again We see Item 93 has been added that it's now demonstrate the porter upgrade operation. Let's change item price off waits to 10.99 So let me copy this change. The method to put Henry will be content Time application slash Nissan request body will be custom They based that is on here change the price to 10.99 and hurt center Quist and it has been updated. There is very fire with the get call. So I don't mind the one to us from the history for the get call change the i d to one and clicks and request and we see that our of rage was successful Finally, that I see the delete operation in action. Let us delete at M I. T three, which we inserted earlier, So let me change the method or delete it expects it a quest parameter. So let me make the change with a question mark and value off ideas. Three. Hittson. And to see the success responds, let's call the get all matter again. And indeed, either minded three are deleted. So hopefully this demo give you a good understanding of how to create Kurt operations against our object. Next that will see how spring boot makes it easy for us to consume the rest services. 9. Demo: Consuming REST Services: In this demo, we will see how we consume rest services using spring boot. It will take the spring embassy product. We had creature in the earlier course spring good fundamentals, connecting to read a base. And instead of fetching data from our database, we will display the front end consuming data from the rest. Epi ice will make a copy of the APP, remove the GW's linkages, modify the service layer toe, fetch the data and perform Kurt operations using the A P A. Calls Worse is fetching it from the Red Abi's. All right, let's get started now. Here is the spring NBC project we had created an hour earlier. Video spring. Good fundamentals. Connecting to a database like we started it is running a board 80 80. Let me go to the browser. Good girl HDB local host 80 80 slash and wintry slash all, and we see the list of items we can edit at New item on delete atom. Currently, this is happening against a back and my secret database. Let's stop the AMP There is an error for SSL exception, which I believe is a bug with the my sequel connector. Probably it will go away with diversion off my sickle connector at the time we try this demo. But as a work around that is, open the application or properties file Any gun port they used as a cyclical toe falls in the data source. Your L Toe Award This error. Let me make a copy off this app basted. Give it a name. Spring consume, rest. Let's open the APP. Let me clear the console. Close the application or properties file. Currently the item service classes performing crowd operations using the GP repository interface. Let's delete the repository package in the class. Next, let's go to the application of properties file and remove all the database and connection pooling properties. Next, let's delete the important equal file. Let's open the Bondra XML file and remove the G p A and my secret dependencies. So essentially we have dealing this AB from a back end database. Next, let's go to our model package. Open the items entity, remove the ad entity notation the at idee notation. The generation. In addition, the only reason we have the entity hair is as arrest FBI's recruiter turning it, and we can have spring to the translation off the Jason toe this entity for us at the ad disowning your properties. Ignore unknown. Equally true with states that ignore any properties, not bone to this type. Open the main class or here let us define a bean, which will return a new rest template defending of being like this will then help spring registering it. And so we cannot a white it in our service class, that is, open the application or properties file and change the several port to 80 82 so that it does not conflict with the rest FBI app for Richard Tomcat is also listening on Port 80 80 . So let's open our service class and fix these errors. Let us order wire over s template as variable RST fixed the imports. Next for the get Mitter, let us get the item by calling RST dot Get for object. Put in our girl issue dp local host a deity slash FBI slash items plus item i d We're attaching the item ideas apart parameter the response types items dot class They don't know you are I really bills. We print the item name and return the item. Let us remove the optional from the redone signature. Next Lex Change. To get all matter to pull from the FBI, we will receive a response as response entity off type list off items. So this time we will call the artist. You don't Exchange meter, which will take in the U. R L. The issue to be method, which is get the entity headers and our body to write to the request were passing Mel for it and parameter rised type reference is used pass generate type information. So list of items number case which you better turn back by the FBI. There are no you are I variables. Let's fix the imports within up in the list of items were calling response toward get more emitter. Let's bring the items size and then return the items. The implementation for insert and abrade method is straightforward where you call the honesty that post for object mentored, which takes in the FBI the item to insert or update and the type of the object here. Attempted art class There are no you are I variables for the delete mattered that is called a listed or delete passing in the D League FBI passing in their quest parameter of ideas. Item don't get item i d. Going to the controller. Let's fix the errors. Essentially, we're learning now. Item worse is the optional items as before, So let's fix that similarly hair. Let's remove the I don't get now our control methods. Stay the scene. Call the service mentors as before. Does that This time the service matures. Are fetching data from the rest? EPA calls Let's go to the springboard dashboard and first started arrest. FBI App. It got started listening at Port 80 80. Next, let's start over Consumer app, which get started and Port 80 82. Let's go to http local host. 80 82 slash and wintry slash all. And here we see over front end, pulling in data from the rest API eyes. Let's edit an item at a new item civet, and it shows up here. Let's delete it and it's gone. So all the a p A. Cause. They're working just fine with this. We have reached to an end of the scores. Let's go in. Summarize what we talked about 10. Summary: in this course, we started off talking about the audience for the scores. Tools needed to be successful and prerequisites, if any. We saw how spring boot makes it easy to create and consume arrest based Web services. He started off creating wrist endpoints for the current operations against our items object . We tested them using a risk lined in our case, that insert extension for the Firefox browser. Next we took the spring and Missy AB we had been earlier in the course springboard fundamentals. Can it contribute Abi's and it sort of fudging data from Madrid Abi's. We displayed the front end consuming data from the rest api eyes. I certainly enjoy creating this course, and I hope you found it useful. I wish you the very best as you apply this knowledge to your projects creating powerful applications. He wasn't string boot