hcoa / todo-api-phoenix

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status

TodoApi

This is a sample for todo api CRUD. Generated by phoenix framework.

To start Phoenix app:

  • Install dependencies with mix deps.get
  • Create and migrate your database with mix ecto.create && mix ecto.migrate
  • Start Phoenix endpoint with mix phoenix.server

Now you can go to localhost:4000/api/todos from browser.

Run in docker with compose

docker-compose should be installed

Run todo_api and postgres db in detached mode

docker-compose up -d

after create and migrate db

docker-compose run web mix do ecto.create, ecto.migrate

Now you can create new items. Example with curl:

create new item:

curl -XPOST http://localhost:4000/api/todos \
    -H 'Content-type: application/json' \
    --data '{"todo": {"description":"create todo", "complete":true}}'

get all items:

curl http://localhost:4000/api/todos

update item:

curl -XPUT http://localhost:4000/api/todos/1 \
    -H 'Content-type: application/json' \
    --data '{"todo", {"description":"update todo", "complete":false}}'

delete item:

curl -XDELETE http://localhost:4000/api/todos/1 \

turn off:

docker-compose down

Deploying to AWS ECS

ecs-cli should be installed.

  1. Configure ecs. docs
ecs-cli configure --region us-west-2 --access-key $AWS_ACCESS_KEY_ID --secret-key $AWS_SECRET_ACCESS_KEY --cluster ecs-cli-demo
  1. Run with command:
ecs-cli compose --file docker-compose.yml up

More commands can be found in official documentation

About


Languages

Language:Elixir 100.0%