Skip to content

gabrielsmartins/quarkus-movie-service

Repository files navigation

Quarkus Movie Service

Quarkus Movies Service CI

This project uses Quarkus, the Supersonic Subatomic Java Framework.

If you want to learn more about Quarkus, please visit its website: https://quarkus.io/ .

See my article on Medium

Follow the instructions to setup the environment

  1. Download AWS Cli
  2. Configure AWS Cli:
$ aws configure
  • AWS Access Key ID: movie-service
  • AWS Secret Access Key: movie-service
  • Default region name: sa-east-1
  • Default output format: json
  1. Clone localstack:
$ git clone https://github.com/localstack/localstack.git
  1. Run localstack:
docker-compose up -d
  1. Create tables:
$ aws --endpoint http://localhost:4566 dynamodb \
 create-table --table-name Movies \
 --attribute-definition AttributeName=Id,AttributeType=S \
 --key-schema AttributeName=Id,KeyType=HASH \
 --billing-mode PAY_PER_REQUEST

Follow the instructions to run the application

You can run your application in dev mode that enables live coding using:

./mvnw compile quarkus:dev

NOTE: Quarkus now ships with a Dev UI, which is available in dev mode only at http://localhost:8080/q/dev/.

The application can be packaged using:

./mvnw package

It produces the quarkus-run.jar file in the target/quarkus-app/ directory. Be aware that it’s not an über-jar as the dependencies are copied into the target/quarkus-app/lib/ directory.

The application is now runnable using java -jar target/quarkus-app/quarkus-run.jar.

If you want to build an über-jar, execute the following command:

./mvnw package -Dquarkus.package.type=uber-jar

The application, packaged as an über-jar, is now runnable using java -jar target/*-runner.jar.

You can create a native executable using:

./mvnw package -Pnative

Or, if you don't have GraalVM installed, you can run the native executable build in a container using:

./mvnw package -Pnative -Dquarkus.native.container-build=true

You can then execute your native executable with: ./target/quarkus-movies-service-1.0.0-SNAPSHOT-runner

If you want to learn more about building native executables, please consult https://quarkus.io/guides/maven-tooling.

This application has the following features:

Use the following example to create a new movie:

Request

curl --location --request POST 'http://localhost:8080/movies/v1' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name": "Rocky Balboa",
    "genre": "ACTION",
    "year": 1976,
    "duration": "01:59",
    "directed_by": "John G. Avildsen",
    "actors": [
        {
            "name": "Sylvester Stallone",
            "role": "Rocky Balboa",
            "dob": "1946-07-06",
            "gender": "M"
        }
    ]
}'

Response

{
  "id": "c63fa101-b2a9-446b-99d7-6911ffa82ee7",
  "name": "Rocky Balboa",
  "genre": "ACTION",
  "year": 1976,
  "directed_by": "John G. Avildsen",
  "duration": "01:59",
  "actors": [
    {
      "name": "Sylvester Stallone",
      "role": "Rocky Balboa",
      "dob": "1946-07-06",
      "gender": "MALE"
    }
  ]
}

Use the following example to update a movie:

Request

curl --location --request PUT 'http://localhost:8080/movies/v1/c63fa101-b2a9-446b-99d7-6911ffa82ee7' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name": "The Godfather",
    "genre": "DRAMA",
    "year": 1972,
    "duration": "02:55",
    "directed_by": "Francis Ford Coppola",
    "actors": [
        {
            "name": "Marlon Brando",
            "role": "Vito Corleone",
            "dob": "1924-04-03",
            "gender": "M"
        }
    ]
}'

Response

{
  "id": "c63fa101-b2a9-446b-99d7-6911ffa82ee7",
  "name": "The Godfather",
  "genre": "DRAMA",
  "year": 1972,
  "directed_by": "Francis Ford Coppola",
  "duration": "02:55",
  "actors": [
    {
      "name": "Marlon Brando",
      "role": "Vito Corleone",
      "dob": "1924-04-03",
      "gender": "MALE"
    }
  ]
}

Use the following example to search movie by ID:

Request

curl --location --request GET 'http://localhost:8080/movies/v1/c63fa101-b2a9-446b-99d7-6911ffa82ee7'

Response

{
  "id": "c63fa101-b2a9-446b-99d7-6911ffa82ee7",
  "name": "Rocky Balboa",
  "genre": "ACTION",
  "year": 1976,
  "directed_by": "John G. Avildsen",
  "duration": "01:59",
  "actors": [
    {
      "name": "Sylvester Stallone",
      "role": "Rocky Balboa",
      "dob": "1946-07-06",
      "gender": "MALE"
    }
  ]
}

Use the following example to search movies by name:

Request

curl --location --request GET 'http://localhost:8080/movies/v1?name=Rocky' 

Response

{
  "data": [
    {
      "id": "622a86dc-3f22-4be3-87d8-619e9cdaa88a",
      "name": "Rocky Balboa",
      "genre": "ACTION",
      "year": 1976,
      "directed_by": "John G. Avildsen",
      "duration": "01:59",
      "actors": [
        {
          "name": "Sylvester Stallone",
          "role": "Rocky Balboa",
          "dob": "1946-07-06",
          "gender": "MALE"
        }
      ]
    }
  ],
  "page_size": 30,
  "page_number": 0,
  "total_pages": 1,
  "total_elements": 1
}

Use the following example to search all movies:

Request

curl --location --request GET 'http://localhost:8080/movies/v1/' 

Response

{
  "data": [
    {
      "id": "622a86dc-3f22-4be3-87d8-619e9cdaa88a",
      "name": "Rocky Balboa",
      "genre": "ACTION",
      "year": 1976,
      "directed_by": "John G. Avildsen",
      "duration": "01:59",
      "actors": [
        {
          "name": "Sylvester Stallone",
          "role": "Rocky Balboa",
          "dob": "1946-07-06",
          "gender": "MALE"
        }
      ]
    },
    {
      "id": "c63fa101-b2a9-446b-99d7-6911ffa82ee7",
      "name": "The Godfather",
      "genre": "DRAMA",
      "year": 1972,
      "directed_by": "Francis Ford Coppola",
      "duration": "02:55",
      "actors": [
        {
          "name": "Marlon Brando",
          "role": "Vito Corleone",
          "dob": "1924-04-03",
          "gender": "MALE"
        }
      ]
    }
  ],
  "page_size": 30,
  "page_number": 0,
  "total_pages": 1,
  "total_elements": 2
}

Use the following example to delete a movie:

Request

curl --location --request DELETE 'http://localhost:8080/movies/v1/c63fa101-b2a9-446b-99d7-6911ffa82ee7'
  • AWS CLI (guide): Install AWS CLI
  • AWS Localstack (guide): Run AWS Localstack
  • RESTEasy Reactive (guide): A JAX-RS implementation utilizing build time processing and Vert.x. This extension is not compatible with the quarkus-resteasy extension, or any of the extensions that depend on it.

Easily start your Reactive RESTful Web Services

Related guide section...

About

Example of Movie Microservice using Quarkus and Localstack

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages