Getting Started ‐ Phase 3 - softwareconstruction240/softwareconstruction GitHub Wiki
The Starter Code has three folders: dataAccess
, serverTests
, and web
. Complete the following steps to move the starter code into your project for this phase.
-
Open your chess project directory.
-
Copy the
starter-code/3-web-api/server
folder into theserver/src/main/java
folder. This contains a basic implementation of an HTTP server that allows the pass off tests to programmatically start and stop your server, as well as the code to host a web browser interface for experimenting with your endpoints. -
Copy the
starter-code/3-web-api/dataaccess
folder into theserver/src/main/java
folder. This contains an exception class that you will throw whenever there is a data access error. -
Create the folder
server/src/test/java
. Right click on the folder and select the option to mark the directory astest sources root
. This tells IntelliJ where to look for code to run as tests. -
Copy the
starter-code/3-web-api/passoff
folder into theserver/src/test/java
folder. Thepassoff/server
folder contains the server test cases. -
Create the folder
server/src/main/resources
. Right click on the folder and select the option to mark the directory asresources root
. This tells IntelliJ that it should include the directory when compiling the code to yourout
directory. -
Copy the
starter-code/3-web-api/resources/web
folder to theserver/src/main/resources
folder. Theweb
folder contains the files that implement the web browser interface for experimenting with your endpoints.
This should result in the following additions to your project.
└── server
└── src
├── main
│ ├── java
│ │ ├── server
│ │ │ └── Server.java
│ │ └── dataaccess
│ │ └── DataAccessException.java
│ └── resources
│ └── web
│ ├── favicon.ico
│ ├── index.css
│ ├── index.html
│ └── index.js
└── test
└── java
└── passoff
└── server
└── StandardAPITests.java
There is a lot of 3rd party code that you can download and include in your Java applications. As part of the starter project, we already included packages that run your JUnit tests and process JSON. We now need to install another third party package to help us create an HTTP server.
We are going to use a cloud based package repository called Maven. Using IntelliJ, you can add a package by opening the project settings and going to the modules
tab. Select the module you wish to add a dependency to. Press the +
button and select from Maven...
. You then supply the name of the library you want to download. Once it is added, you can specify the scope
for the dependency. Most dependencies for this class will be with scope "compile", meaning that the dependency is available to all the code in the module when it compiles. There are a few others, including "test", which means it is only available for code used to test the code in the module.

Add the dependencies for using JavaSpark to your server
module.
-
com.sparkjava:spark-core:2.9.3 - Handles HTTP requests and registers handlers for endpoints.
- Scope: Compile
-
org.slf4j:slf4j-simple:1.7.36 - Logger for SparkJava.
- Scope: Compile
Once you have completed all of the previous steps you should be able to launch your server and access a testing page. This is a dummy frontend that was made to help with basic testing of your server and endpoints.
Inside of server/src/main/java/Main.java
in the main method, create a Server object, and then call run on it. The run method needs the port you will run your server on, which typically for testing is 8080. When you run the main method it will start the server. Intelij will give you several lines of red text, but if the last line says 'started' then the server is active.
Open a browser and go to localhost:8080
(If you picked another port replace 8080 with that instead). If everything is setup correctly you should be able to see this webpage.
You can use this to test your endpoints as you are coding the project.
If you want to see how this works in greater depth or need help troubleshooting, take a look at this page.