Giter Club home page Giter Club logo

zio-akka-starter's Introduction

Running application locally

The application server expects a PostgresQL database to run Flyway migrations. If it can't find one it'll retry forever until successful. This way it doesn't matter what is started first - the application or the database.

Database server

Run the local development database with docker. Replace values for POSTGRES_DB and POSTGRES_PASSWORD according to your settings.

docker run --name devdb --network host -e POSTGRES_DB=items -e POSTGRES_PASSWORD=12345 -d postgres

if you are using docker on Windows or Mac please use the following command, because the host networking driver only work on Linux hosts. reference at https://docs.docker.com/network/host/

docker run --name devdb -p 5432:5432 -e POSTGRES_DB=items -e POSTGRES_PASSWORD=12345 -d postgres

Connect with psql:

psql -h localhost -U postgres -d items

Connect with docker:

docker exec -it devdb psql -U postgres -d items

Application server

To run the application locally:

sbt run

After you run the application Flyway will run the migrations.

By default the server is started at http://localhost:8080. Expects the databse at localhost:5432 with database name items and user/password postgres/12345.

You can override the defaults with the following environment variables:

  • API_HOST
  • API_PORT
  • DB_HOST
  • DB_PORT
  • DB_NAME
  • DB_USER
  • DB_PASSWORD

Testing

Run unit tests:

sbt test

Run integration tests:

sbt it:test

The integration tests are using testcontainers to run dockerized PostgrSQL instance and Flyway to apply schema evolutions before running the tests.

Calling the endpoints

Add new Item:

curl --request POST \
  --url http://localhost:8080/items \
  --header 'content-type: application/json' \
  --data '{
	"name":"BigMac",
	"price": 10.0
}'

Get all Items:

curl --request GET \
  --url http://localhost:8080/items

Get single Item:

curl --request GET \
  --url http://localhost:8080/items/1

Update Item:

curl --request PUT \
  --url http://localhost:8080/items/1 \
  --header 'content-type: application/json' \
  --data '{
	"name":"BigKing",
	"price": 12.0
}'

Detele Item:

curl --request DELETE \
  --url http://localhost:8080/items/1

Database schema evolution

Schema evolution is done using Flyway.

To add more evolutions add the new scripts to resources/db/migration.

Read more about Flyway here.

Creating a docker image

This project is configured with sbt-native-packager. To publish a docker image to your local docker repository run:

sbt docker:publishLocal

This will create an image with name zio-akka-quickstart:<version>.

zio-akka-starter's People

Contributors

icemc avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.