This is a website for tracking the beers that I brew for the office and at home. This project is also to learn some new technologies.
- SASS
- React
- Various other libs
- Java 8 and JEE 7.0
- Maven
- WildFly
- A Postgres DB
- Ruby (For SASS)
Database Server = localhost
Database Name = mybrews
Database Password = welcome1
Database Username = mybrews
These can be changed in the pom.xml
If you do not have postgresql, here are the steps for setup/install on linux.
sudo apt-get install -y postgresql-client postgresql postgresql-contrib pgadmin3
pgadmin3 is optional. It is the GUI tool.
Once it is installed, you can connect with:
sudo -u {db-user} psql {db-name}
I usually create a new linux user for each user in the database. Probably not required.. Just can't figure out out otherwise. The command (in Ubuntu) is
sudo useradd {username}
To create the database and user for the default configuration in the pom.xml
sudo -u postgres createuser -D -A -P mybrews
sudo -u postgres createdb -O mybrews mybrews
sudo -u mybrews psql -d mybrews -a -f src/main/scripts/tables.sql
This will use the postgres admin user to create a new user mybrews that only has privileges over the new database mybrews. The first command will also prompt for you to enter a password. The third command will run the tables.sql database script as the mybrews user in the new mybrews db.
Navigate to http://rubyinstaller.org/ and choose your correct download. This is to install Ruby with the rubygems. Once
Once you have ruby and rubygems, verify that they are in your path with ruby -v
and gem -v
. If they are in your path, you can install sass with
gem install sass
Linux might require sudo.
Start up your wildfly node and run
mvn install
Will add the postgresql.jar
to your wildfly server and add the MyBrewsDS data source.
To build and deploy the application, run
mvn wildfly:deploy
The front end app requires npm
and gulp
to be built and manage dependencies.
Currently, the front end app is only set for development and is running off of browsersync
To install any dependencies, run npm install
. If new scss depdendencies have been added or this is your first time cloning, run npm run symlinks
which will create the symlinks in the src/main/app/scss/vendors
directory. You can view the README.md there as well. (Creating the symlinks will require Admin for Windows).
To install gulp, run npm install -g gulp
.
Once your dependencies have been set up and gulp has been isntalled, you can launch the front end app with
gulp
Super simple! It will distribute all the files in a dist
folder and open up your browser to localhost:3000
and you can view the app.
Resource used for planning RESTful web services: http://www.restapitutorial.com/lessons/httpmethods.html
This application is pretty much just create, retrieve, update, and delete.
Well.. now that I think about it, probably not too much delete. To keep consistent, I created an interface for each method so they will all have the same path when fully implemented.
Any time there is an {entityName}, it is a pluralized version.
Any entity will be retrieved just by sending a GET
request to /api/{entityName}/{id}. An HTTPResponse will be returned with the entity (if found). If the entity is not found, Status Code 404 (Not Found) will be returned, otherwise 202 (OK) with the entity as json.
To retrieve all of a single entity, send a GET
request to /api/{entityName}.
Some example curl calls:
curl -iX GET localhost:8080/my-brews/api/beers
curl -iX GET localhost:8080/my-brews/api/beers/1
The first call will retrieve all beers and the second call will attempt to find beer with id 1. Since there currently is no data for beer, try these curl requests (constants).
curl -iX GET localhost:8080/my-brews/api/beerstyles
curl -iX GET localhost:8080/my-brews/api/beercolors/1
The first call will retrieve all beer styles and the other call will return the beer color with id 1.
Any entity can be created by sending a POST
request to /api/{entityName}.
An example curl call:
curl -H "Content-Type: application/json" \
-d '{"name": "Wyeast #1332 Northwest Ale Yeast", "type": "LIQUID"}' \
-i localhost:8080/my-brews/api/yeasts
This will create a new yeast with the name and given Yeast Type. This will return a status of 201 (Created) if successful along with a Location header with a link to the new resource. A successful create would return something like this:
HTTP/1.1 201 Created
Connection: keep-alive
X-Powered-By: Undertow/1
Server: WildFly/8
Location: /api/yeasts/1
Content-Length: 0
Date: Thu, 12 Mar 2015 00:19:51 GMT
An entity can be updated by sending a PUT
request to /api/{entityName}
This might get updated later to pass in the id as well.. ex: /api/{entityName}/{id}. I'm not sure what I like yet.
An example update of the yeast we just created:
curl -H "Content-Type: application/json" \
-X PUT -d '{"id": "1", "name": "Wyeast #1332 Northwest Ale Yeast", "type": "DRY"}' \
-i localhost:8080/my-brews/api/yeasts
This updates the yeast we just created to have a DRY yeast type. Super exciting!!!
An entity can be deleted by sending a DELETE
request to /api/{entityName}/{id}. So lets delete that yeast we just created:
curl -iX DELETE localhost:8080/my-brews/api/yeasts/1
Wala! Magic!
If you are interested in viewing the javadoc that is a part of this project and viewing all the dependencies, you can run
mvn site
which will generate a maven site with all dependencies and generated javadoc in your /target/site
folder which you can then open and view in a browser.