Skip to content

API Elixir and PostgreSQL with Plug (Standalone)

Notifications You must be signed in to change notification settings

gilcierweb/api-elixir

Repository files navigation

API Elixir and PostgreSQL with Plug (Standalone)

Mix generate project without frameworks(No Phoenix, No Maru and etc)

Skills

  • Elixir
  • PostgreSQL

Setup Elixir (local)

https://asdf-vm.com/#/core-manage-asdf

https://github.com/asdf-vm/asdf-erlang

https://github.com/asdf-vm/asdf-elixir

Development without docker

mix do deps.get, deps.compile, compile
mix ecto.create 
mix ecto.migrate

MIX_ENV=test mix ecto.create
MIX_ENV=test mix ecto.migrate
MIX_ENV=test mix test

iex -S mix

mix run --no-halt # run http://localhost:4000

run in local http://localhost:4000

List All Routes

# get http://localhost:4000
# get http://localhost:4000/gilcierweb
# post http://localhost:4000/checkout # payload order
# get http://localhost:4000/checkout/success # success order payment gateway
# get http://localhost:4000/admin/authorized 
# get http://localhost:4000/admin/unauthorized
# get http://localhost:4000/api/secret
# get http://localhost:4000/api/open

post http://localhost:4000/checkout # payload order

{
  "id": 9987071,
  "store_id": 282,
  "date_created": "2019-06-24T16:45:32.000-04:00",
  "date_closed": "2019-06-24T16:45:35.000-04:00",
  "last_updated": "2019-06-25T13:26:49.000-04:00",
  "total_amount": 49.9,
  "total_shipping": 5.14,
  "total_amount_with_shipping": 55.04,
  "paid_amount": 55.04,
  "expiration_date": "2019-07-22T16:45:35.000-04:00",
  "total_shipping": 5.14,
  "order_items": [
    {
      "item": {
        "id": "IT4801901403",
        "title": "Produto de Testes"
      },
      "quantity": 1,
      "unit_price": 49.9,
      "full_unit_price": 49.9
    }
  ],
  "payments": [
    {
      "id": 12312313,
      "order_id": 9987071,
      "payer_id": 414138,
      "installments": 1,
      "payment_type": "credit_card",
      "status": "paid",
      "transaction_amount": 49.9,
      "taxes_amount": 0,
      "shipping_cost": 5.14,
      "total_paid_amount": 55.04,
      "installment_amount": 55.04,
      "date_approved": "2019-06-24T16:45:35.000-04:00",
      "date_created": "2019-06-24T16:45:33.000-04:00"
    }
  ],
  "shipping": {
    "id": 43444211797,
    "shipment_type": "shipping",
    "date_created": "2019-06-24T16:45:33.000-04:00",
    "receiver_address": {
      "id": 1051695306,
      "address_line": "Rua Fake de Testes 3454",
      "street_name": "Rua Fake de Testes",
      "street_number": "3454",
      "comment": "teste",
      "zip_code": "85045020",
      "city": {
        "name": "Cidade de Testes"
      },
      "state": {
        "name": "São Paulo"
      },
      "country": {
        "id": "BR",
        "name": "Brasil"
      },
      "neighborhood": {
        "id": null,
        "name": "Vila de Testes"
      },
      "latitude": -23.629037,
      "longitude": -46.712689,
      "receiver_phone": "41999999999"
    }
  },
  "status": "paid",
  "buyer": {
    "id": 136226073,
    "nickname": "JOHN DOE",
    "email": "[email protected]",
    "phone": {
      "area_code": 41,
      "number": "999999999"
    },
    "first_name": "John",
    "last_name": "Doe",
    "billing_info": {
      "doc_type": "CPF",
      "doc_number": "09487965477"
    }
  }
}

Development with docker and docker-compose

docker-compose build
docker-compose up # run http://localhost:4000
docker-compose run --rm web mix ecto.create
docker-compose run --rm web mix ecto.migrate
docker-compose run --rm web bash

run with docker http://localhost:4000

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/api_elixir.

https://gilcierweb.com.br/