Skip to content

Implementing a REST API to simulate a deck of cards.

Notifications You must be signed in to change notification settings

HazemNoor/card-game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Another Card Game

An implementation of a REST API to simulate a deck of cards.

Credit

Hazem Noor [email protected]

How to run this code

  1. At least go1.18 and docker needs to be installed
  2. You can see list of commands using make command
make
  1. Run tests
make test
  1. Start the Redis server by docker
make start-redis

it will run on port 6379 by default, you can change from .env file

  1. Build and Start the binary
make start

it will run on port 8000 by default, you can change from .env file

the binary file will be located in bin directory


To stop the server hit Ctrl+C

Don't forget to stop redis too with make stop-redis


API Documentation

  • Create a new Deck
curl --request PUT --url 'http://localhost:8000/deck?shuffled=1&cards=AS,KD,AC'

Response would be

{
    "deck_id": "05d5b426-a086-48d5-ad9c-1c913774154b",
    "shuffled": true,
    "remaining": 3
}
  • Open a Deck
curl --request GET --url 'http://localhost:8000/deck/05d5b426-a086-48d5-ad9c-1c913774154b'

Response would be

{
    "deck_id": "05d5b426-a086-48d5-ad9c-1c913774154b",
    "shuffled": true,
    "remaining": 3,
    "cards": [
        {
            "value": "KING",
            "suit": "DIAMONDS",
            "code": "KD"
        },
        {
            "value": "ACE",
            "suit": "SPADES",
            "code": "AS"
        },
        {
            "value": "ACE",
            "suit": "CLUBS",
            "code": "AC"
        }
    ]
}
  • Draw a Card
curl --request POST --url 'http://localhost:8000/deck/05d5b426-a086-48d5-ad9c-1c913774154b/draw?count=2'

Response would be

{
    "cards": [
        {
            "value": "ACE",
            "suit": "SPADES",
            "code": "AS"
        },
        {
            "value": "KING",
            "suit": "DIAMONDS",
            "code": "KD"
        }
    ]
}

About

Implementing a REST API to simulate a deck of cards.

Topics

Resources

Stars

Watchers

Forks