This is part two of our series where we are going to walk through a full stack development exercise that we have put together for our Unosquare University curriculum. With our internal University we are creating a place where we can centrally house various courses and learning materials for the technologies where our teammates excel. Some of our curriculum has been helpful to software development professionals outside of Unosquare, and we hope that you find this interesting and helpful.
In part one we ended with a working API and now we are going to create our database using MySQL 8.0. Now, you may notice that the file names in some of the images in this post are in Spanish, but we think that this is easy enough to follow along. The development talent at Unosquare is bilingual, and so are our File Explorers ; )
We want our database to be durable, able to change with devices and software. Therefore, we are going to create a persistent database so that our data is stable and recoverable.
As we mentioned in the introduction, we are going to create our database using MySQL 8.0. Here is an image of our table.
Data Source: GlassFish
We’ll take advantage of our GlassFish container to set a data source which will be used by our application.
1. First and foremost, you have to add your mysql-connector (or whatever connector you wish to use) jar file to GlassFish.
2. Go to http://localhost:4848
3. Create a new connection pool:
4. Add your connection settings:
5. Create a resource with your recently created connection pool:
Now, we have the four main verbs for for our RESTful API: GET, PUT, POST and DELETE
FINAL STEP: Enabling CORS (Cross-Origin Resource Sharing)
We already have our RESTful API running, but we are missing an important detail. We need to enable our application to receive requests from different origins and configure what kind of requests and formats could accept.
This is very important. If this is not set up correctly, communication between the back-end and the front-end will not be established
To do this we will create a new package (i.e. com.rest.security) and we will add a new class: