Quick Start
This quick start guide assumes you have all the prerequisites installed. If you’re unsure of what you need, see the Prerequisites page for more information.
Clone the project repositories
The project is split into two repositories called canyonlands-spring-api
and
canyonlands-angular-app
respectively.
The back-end project can be found at the following link:
Back-end API
Execute the following command in your Terminal:
You should now have a directory called canyonlands-spring-api
on your local file system.
Back-end API setup, start and test
This project makes use of Docker to run the required infrastructure locally.
In your Terminal window navigate to the root of the project directory, there is a
docker-compose.yml
file that contains the configuration for the project’s database and
identity provider.
To bootstrap the PostgreSQL
database and the Keycloak
service, run the following
docker-compose
command in your Terminal:
Upon successful execution of the command, you can verify that the containers are running with the following command:
You should see the following output:
The NAMES
column should show the names of the containers that are running.
The canyonlands-db
container is the PostgreSQL database container and the keycloak
container
is the Keycloak identity provider container.
Before starting the back-end project, you need to configure the environment variables.
Inside the root of the project, there is a .env.template
file that contains the variable names
to be set. Copy the contents of the .env.template
file to a new file named .env
and set the
values accordingly.
Directorysrc
Directorymain
Directoryjava
- …
- README.md
- .env.template copy contents
- .env create this
- …
The default values for the environment variables are as follows:
Start the back-end API
The canyonlands-spring-api
project makes use of Gradle
to manage the project’s dependencies
and to run the development server.
To start the development server, you have a few options:
-
IntelliJ IDEA: If you open the project in IntelliJ IDEA, you need to attach the
.env
file to the run configuration.In the
Build and Run
section of the run configuration, click on theEnvironment variables
to toggle the environment variables section. Once there, click on the...
button and add the.env
file found in the root of the project. -
Command Line: The project comes with a
Gradle
wrapper that can be used to start the development server. Thebuild.gradle
file contains the necessary configuration to inject the.env
file into the run configuration task.You can start the development server by running the following command in your Terminal:
To verify that the back-end API is running, check the application log output and verify that there aren’t any errors. You should look for the following lines in the log:
You can also execute the following cURL
command in the Terminal to check the health endpoint
of the API:
You should see the following output:
Postman collection and environment
A Postman collection and environment export can be found in the project’s docs
directory.
- …
Directorydocs
Directoryapi
- Local.postman_collection.json
- Local.postman_environment.json
Directorysrc
- …
- README.md
- …
Obtain an OAuth token
In order to interact with any of the API endpoints on the back-end application (apart from the health endpoint) you will need to have a valid OAuth token attached in the request.
There’s a preloaded user in the Keycloak realm, the details for the user is as follows:
This user has a role value of SYS_ADMIN
which means it can execute authenticated calls to any
of the API endpoints.
-
Perform a Login and get a token:
Make use of the username and password combination above and execute the following cURL request:
-
This should provide a response like:
-
Copy the
access_token
value for use in subsequent API calls.
Perform authenticated API request
The first action to perform should be to register the user. We’ll make use of the
access_token
copied in the previous step to make an authenticated API call to the /register
endpoint.
The access_token
contains various claims within the token. These include:
- preferred_username
- given_name
- family_name
These values are decrypted in the back-end application and used to insert a new user object into
the database. A unique userID
will be generated upon successful insertion of the new user.
This “localized” userID
value is used throughout the application to keep track of user
specific data.
Upon executing the above request you should receive a successful response with an HTTP status
code of HTTP 201 Created
.
If you look at the application logs you should see something like the following:
Extra credit — Retrieving all users
In order to retrieve a list of all users in the system make an authenticated API call to the
/users
endpoint.
Upon executing the above request you should receive a successful response with an HTTP status
code of HTTP 200 OK
and a response body like the following: