This is a simple Spring Boot REST API Proof of Concept (POC) project.
The goal of this project is to demonstrate how to create a REST API using Spring Boot, and it can run properly in the Render ecosystem.
The idea to create this project arises in response to several questions asked by participants of the Devs Latam initiative from the TryCatch development community.
The following is the list of technologies used to build this project:
- Java 17
- Spring Boot 3.0.6
- Apache Maven 3.9.1
- Lombok 1.18.26
- OpenAPI 3.0.3
- PostgreSQL 15
- Docker 20.10.24
- Render
To create a PostgreSQL database in Render, you need to follow the following steps:
- Go to the Render's dashboard.
- Click on the New+ button, and then click on the PostgreSQL option.
- In the New PostgreSQL form, you need to fill the following fields:
- Name: The name of the database resource in Render.
- Database: The name of the database instance.
- User: The username of the database.
- Region: The region where the database will be created.
- PostgreSQL Version: The PostgreSQL version. I recommend using the latest version.
- Instance Type: The instance type. I recommend using the Free instance type for academic purposes.
- Click on the Create Database button.
To build this project, you need to have the following installed on your machine:
- Java 17
- Apache Maven 3
- Docker 20
To build the project, you need to run the following command:
mvn clean package
NOTE: This command must be executed in the root directory of the project.
To build the Docker image, you need to run the following command:
docker build -t render-spring-boot-rest-api-poc .
NOTE: This command must be executed in the root directory of the project.
To run the Docker container, you need to run the following command:
docker run -e DB_URL="DB_URL" -e DB_USER=DB_USER -e DB_PASSWD=DB_PASSWD -p 8080:8080 render-spring-boot-rest-api-poc
Where:
DB_URL
is the URL of the PostgreSQL database.DB_USER
is the user of the PostgreSQL database.DB_PASSWD
is the password of the PostgreSQL database.
These data must be provided as environment variables to the Docker container, and they can be obtained from the Render's database resource, within the Connections section.
Example:
docker run -e DB_URL="jdbc:postgresql://postgres.render.com:5432/render-spring-boot-rest-api-poc" -e DB_USER=postgres -e DB_PASSWD=postgres -p 8080:8080 render-spring-boot-rest-api-poc
To deploy this project on Render, you need to follow the following steps:
- Go to the Render's dashboard.
- Click on the New+ button, and then click on the Web Service option.
- In the Create a new Web Service form, you need to fill the following fields:
- Connect a repository: Select the repository where the project is located. Click on the Connect button to continue.
- In the next form, you need to fill the following fields:
- Name: The name of the web service.
- Region: The region where the web service will be created.
- Branch: The branch of the repository to deploy.
- Runtime: The runtime of the web service. For this case, you need to select the Docker option.
- Instance Type: The instance type. I recommend using the Free instance type for academic purposes.
- In the Advanced section, click the Add Environment Variable button, and then add the following environment variables:
- PORT: The port where the web service will be listening. For this case, you need to use the 8080 value.
- DB_URL: The URL of the PostgreSQL database.
- DB_USER: The user of the PostgreSQL database.
- DB_PASSWD: The password of the PostgreSQL database.
- Click the Create Web Service button.
To use this project, you need to follow the following steps:
- Use Postman or any other tool to make HTTP requests. You can find the OpenAPI specification of this project in the
/v3/api-docs
endpoint of the web service. - You can use the Swagger UI to make HTTP requests. You can find the Swagger UI in the
/swagger-ui/index.html
endpoint of the web service.
This project is licensed under the MIT License - see the LICENSE file for details
- TryCatch - Social Media Links
This project is not affiliated, associated, authorized, endorsed by, or in any way officially connected with Render, or any of its subsidiaries or its affiliates. The official Render website can be found at https://render.com. The name "Render" as well as related names, marks, emblems and images are registered trademarks of their respective owners.