Skip to content

maxcnunes/elixir-phoenix-rest-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Elixir Phoenix Rest API

This project is all generated by phoenix framework. Actually I just spent time removing the static files and configuring the application to run with docker. Which is a good point to the framework because at least to the bootstrap makes everything faster and easier.

Cloning this project:

git clone git@github.com:maxcnunes/elixir-phoenix-rest-api.git rest_api

Development

Running Locally

To start your Phoenix app:

  1. Install dependencies with mix deps.get
  2. Set the env variable DATABASE_URL="ecto://user:password@db/rest_api_dev" (you may change the values)
  3. Create and migrate your database with mix ecto.create && mix ecto.migrate
  4. Start Phoenix endpoint with mix phoenix.server

Now you can visit localhost:4000 from your browser.

Running With Docker

  1. Create and migrate your database with docker-compose run --rm local sh -c "mix ecto.create && mix ecto.migrate
  2. Start Phoenix endpoint with docker-compose run --rm local

Now you can visit <container-ip>:<container-public-port> from your browser. Or in case your are using dockito-proxy api.local.dockito.org.

Example requests with CURL

List

curl http://api.local.dockito.org/posts

Create

curl -H "Content-Type: application/json" \
     -X POST \
     -d '{"post": {"title":"Title 001","content":"Content 001"} }' \
     http://api.local.dockito.org/posts

Update

curl -H "Content-Type: application/json" \
     -X PUT \
     -d '{"post": {"title":"Title 001 Updated","content":"Content 001 Updated"} }' \
     http://api.local.dockito.org/posts/1

Delete

curl -X DELETE \
     http://api.local.dockito.org/posts/1

Test

Testing Locally

mix test

Testing With Docker

docker-compose run --rm test

About

A simple example of a rest API with elixir and phoenix

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages