GithubHelp home page GithubHelp logo

rock-paper-scissors's Introduction

๐ŸŽฒ Rock Paper Scissors

REST API that lets developers resolve their differences using the game Rock, Paper, Scissors. The rules are simple, the best of 1 match wins.

๐Ÿš€ Getting started

Prerequisites

How to run

Install dependencies

npm install

Run the tests

npm test

Start the Backend server

npm run build && npm start

๐ŸŒŒ Endpoints

GET /api/games/{id}

Returns the current state of a given game.

Parameters

  • id (required) - The ID of the game to retrieve.

POST /api/games

Creates a new game.

Request-body

  • name (required) - The name of the player.
{
    "name": "foo"
}

POST /api/games/{id}/join

Connects to a game with a given ID.

Parameters

  • id (required) - The ID of the game to retrieve.

Request body

  • name (required) - The name of the player.
{
    "name": "bar"
}

POST /api/games/{id}/move

Make a move.

Parameters

  • id (required) - The ID of the game to retrieve.

Request body

  • name (required) - The name of the player.
  • move (required) - The move to make. Valid moves are rock, paper or scissors
{
    "name": "foo",
    "move": "rock"
}

๐Ÿšจ Error responses

The API may return the following error responses:

  • 400 Bad Request - The request was invalid or missing a required parameter.
  • 404 Not Found - The requested resource could not be found.

๐Ÿ’ฌ Example usage

Player 1 sends a request to create a new game and gets a game ID back from the server.

curl \
-X POST \
-H "Content-Type: application/json" \
-d '{"name": "Foo"}' \
http://localhost:3000/api/games

Player 2 joins the game using the ID.

curl \
-X POST \
-H "Content-Type: application/json" \
-d '{"name": "Bar"}' \
http://localhost:3000/api/games/c7a5de44-c925-4129-af44-c8b3fc40d2a5/join

Player 1 makes a move (Rock).

curl \
-X POST \
-H "Content-Type: application/json" \
-d '{"name": "Foo", "move": "rock"}' \
http://localhost:3000/api/games/c7a5de44-c925-4129-af44-c8b3fc40d2a5/move

Player 2 makes a move (Scissors).

curl \
-X POST \
-H "Content-Type: application/json" \
-d '{"name": "Bar", "move": "scissors"}' \
http://localhost:3000/api/games/c7a5de44-c925-4129-af44-c8b3fc40d2a5/move

Player 1 checks the state of the game and checks who won

curl \
-X GET \
http://localhost:3000/api/games/c7a5de44-c925-4129-af44-c8b3fc40d2a5

Player 2 checks the state of the game and checks who won

curl \
-X GET \
http://localhost:3000/api/games/c7a5de44-c925-4129-af44-c8b3fc40d2a5

rock-paper-scissors's People

Contributors

widdin 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.