Install dependencies
mix deps.get
Set Database URL
export DATABASE_URL="postgres://$(whoami):@localhost/card_shark_dev"
Create database
mix ecto.create
Run database migrations
mix ecto.migrate
Install node dependencies
npm install
bower install
Start server in foreground
mix phoenix.server
Now you can visit card_shark.
iex -S mix phoenix.server
You can execute database actions:
alias CardShark.Repo
alias CardShark.User
users = Repo.all User
changeset = User.changeset(%User{}, %{:email => "[email protected]", :password => "1"})
changeset.valid?
user = Repo.insert changeset
changeset = User.changeset(user, %{:password => "2"})
changeset.valid?
user = Repo.update! changeset
user = Repo.get User, 1
Map.get user, :email
Map.get user, :inserted_at
CardShark.Endpoint.broadcast! "stream", "userevent", %{
event: "created",
user: %{
username: "mark",
content: "content"
}
}
CardShark.Endpoint.broadcast! "stream", "cardevent", %{
event: "created",
card: %{
summary: "manage cards",
detail: "crud operations for managing cards",
estimate: "1",
assignee: "mark"
}
}
Install docker and docker compose.
fig build
fig up
fig run api mix ecto.create
fig run api mix ecto.migrate
heroku apps:create $NAME
heroku buildpack:set https://github.com/HashNuke/heroku-buildpack-elixir
git push heroku master
heroku config:add DATABASE_USERNAME=$USER DATABASE_PASSWORD=$PASSWORD DATABASE_DATABASE=$DATABASE DATABASE_HOSTNAME=$HOSTNAME
heroku run mix ecto.migrate
You can get the values for the required DATABASE environment variables by splitting the heroku generated DATABASE_URL:
heroku config
DATABASE_URL=postgres://$USER:$PASSWORD@$HOSTNAME:5432/$DATABASE
Now you can visit http//$NAME.herokuapp.com
.
export CARD_SHARK_URL=http://127.0.0.1:4000
The cards model, controller, views were initially created with the following generator:
mix phoenix.gen.json Card cards summary:string detail:text estimate:integer assignee:integer
curl $CARD_SHARK_URL/api/cards \
-H 'Content-Type: application/json' \
-X POST \
-d @/dev/stdin <<JSON
{
"card": {
"summary": "manage cards",
"detail": "crud operations for managing cards",
"estimate": "1",
"assignee": "1",
"priority": "30.0",
"status": "todo"
}
}
JSON
curl $CARD_SHARK_URL/api/cards
http $CARD_SHARK_URL/api/cards
curl $CARD_SHARK_URL/api/cards/1
http $CARD_SHARK_URL/api/cards/1
curl $CARD_SHARK_URL/api/cards/1 \
-H 'Content-Type: application/json' \
-X PUT \
-d @/dev/stdin <<JSON
{
"card": {
"summary": "create, read, update, and delete cards"
}
}
JSON
curl $CARD_SHARK_URL/api/cards/1 -X DELETE
curl $CARD_SHARK_URL/api/users \
-H 'Content-Type: application/json' \
-X POST \
-d @/dev/stdin <<JSON
{
"user": {
"email": "[email protected]",
"password": "1"
}
}
JSON
curl $CARD_SHARK_URL/api/users
curl $CARD_SHARK_URL/api/users/1
curl $CARD_SHARK_URL/api/users/1 \
-H 'Content-Type: application/json' \
-X PUT \
-d @/dev/stdin <<JSON
{
"user": {
"password": "2"
}
}
JSON
curl $CARD_SHARK_URL/api/users/1 -X DELETE