Skip to content

This is a Spring Boot application exposing some REST controllers with functionalities to access external API (Marvel API) and provide functionalities as fetch all API data, find data by id and start a simple game.

Notifications You must be signed in to change notification settings

edson-martins/spring-boot-marvel-game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java CI with Maven CodeQL SonarCloud

Spring Boot Marvel Game

Spring Boot Marvel Game is a Java 11+, Spring Boot (version 2.4.4) application accessing the Marvel API’s available at Marvel Developer Portal, exposing REST services to fetch all characters, retrieve a character with an Id and play the game. The idea is only provide a Java code with logics used to access external APIs and provide a functionality as a game and others to retrieve data.

Playing character arena game achieve the following:

  1. Read in 2 superhero names and a seed value between 1-10.

  2. Retrieve the "description" of each hero from the "character" endpoint of the api.

  3. Search the word in the position of the description corresponding to the seed value. As an example, if the provided seed value were 3, will choose the 3rd word in the description for each character.

  4. The hero with the most characters in their word at that position is the winner, but if the word is either "gamma" or "radioactive" that character automatically wins.

  5. Return a Json payload representing the Winner.

Features

  • Java 11+

  • Spring Boot 2.4.4

  • Spring MVC 2.4.4

  • Spring Cloud 2020.0.2

  • Spring Cloud Vault 3.0.2

  • Mapstruct 1.4.2.Final

  • Hashicorp Vault 1.7.0

Setup

  1. Create a new account at https://developer.marvel.com. You will need to generate the keys that will be used in this game.

  2. Install Hashicorp Vault in your machine. Take a look the website https://www.vaultproject.io

  3. After you install Vault, launch it in a console window the command below to starts up a server process.

    1. $ vault server --dev --dev-root-token-id="00000000-0000-0000-0000-000000000000"

  4. Keep the server vault running and in a new window/tab, execute:

    1. $ export VAULT_TOKEN="00000000-0000-0000-0000-000000000000"

    2. $ export VAULT_ADDR="http://127.0.0.1:8200"

    3. $ vault kv put secret/marvel public_key=<your own marvel public key from marvel portal> private_key=<your own private key from marvel portal>

Architecture

Game Architecture

REST Methods

# Method URL Request Response Description

1

GET

/v1/arena/characters/all

N/A

ResponseEntity<RootDTO>

Retrieve all characters

2

GET

/v1/arena/characters/{id}

Long id

ResponseEntity<RootDTO>

Retrieve a character based in the id

3

GET

/v1/arena/games/play

ArenaDTO

ResponseEntity<WinnerDTO>

Play game

#1 - /v1/arena/characters/all

  1. Success Response:

    • Code 200

    • Content:

      {
        "code": 200,
        "status": "Ok",
        "copyright": "© 2021 MARVEL",
        "attributionText": "Data provided by Marvel. © 2021 MARVEL",
        "attributionHTML": "<a href=\"http://marvel.com\">Data provided by Marvel. © 2021 MARVEL</a>",
        "etag": "e0ec184f14a513dbc7a75939ac8dd1933cda7b30",
        "data": {
          "offset": 0,
          "limit": 20,
          "total": 1493,
          "count": 20,
          "results": [
            {
              "id": 1011334,
              "name": "3-D Man",
              "description": "",
              "modified": "2014-04-29T18:18:17.000+00:00",
              "thumbnail": {
                "path": "http://i.annihil.us/u/prod/marvel/i/mg/c/e0/535fecbbb9784",
                "extension": "jpg"
              }
            }
            ...
          ]
        }
      }

#2 - /v1/arena/characters/{id}

  1. Success Response:

    • Code 200

    • Content:

      {
        "code": 200,
        "status": "Ok",
        "copyright": "© 2021 MARVEL",
        "attributionText": "Data provided by Marvel. © 2021 MARVEL",
        "attributionHTML": "<a href=\"http://marvel.com\">Data provided by Marvel. © 2021 MARVEL</a>",
        "etag": "e0ec184f14a513dbc7a75939ac8dd1933cda7b30",
        "data": {
          "offset": 0,
          "limit": 20,
          "total": 1493,
          "count": 20,
          "results": [
            {
              "id": 1011334,
              "name": "3-D Man",
              "description": "",
              "modified": "2014-04-29T18:18:17.000+00:00",
              "thumbnail": {
                "path": "http://i.annihil.us/u/prod/marvel/i/mg/c/e0/535fecbbb9784",
                "extension": "jpg"
              }
            }
          ]
        }
      }
  2. Request Sample

    • /v1/arena/characters/1011334

#3 - /v1/arena/games/play

  1. Request Sample:

    • Content:

      {
         "seed": 4,
         "superheros": [
         {
            "name": "Spider-Man"
         },
         {
            "name": "Hulk"
         }
        ]
      }
  2. Success Response:

    • Code 200

    • Content:

      {
        "id": 1009610,
        "name": "Spider-Man",
        "description": "Bitten by a radioactive spider, high school student Peter Parker gained the speed, strength and powers of a spider. Adopting the name Spider-Man, Peter hoped to start a career using his new abilities. Taught that with great power comes great responsibility, Spidey has vowed to use his powers to help people.",
        "modified": "2020-07-21T14:30:10.000+00:00",
        "thumbnail": {
          "path": "http://i.annihil.us/u/prod/marvel/i/mg/3/50/526548a343e4b",
          "extension": "jpg"
        },
        "word": "radioactive"
      }

About

This is a Spring Boot application exposing some REST controllers with functionalities to access external API (Marvel API) and provide functionalities as fetch all API data, find data by id and start a simple game.

Topics

Resources

Stars

Watchers

Forks

Languages