Skip to content
This repository was archived by the owner on Jan 28, 2020. It is now read-only.

Deck Builder JSON API

TheBuzzSaw edited this page Jul 16, 2015 · 6 revisions

The endpoint /api/decks/submit accepts POST data in the form of a JSON document. If a new deck is being submitted, the deck ID is omitted.

{
    "name": "Jawa X-Wings of DOOM",
    "description": "This deck has never lost... because I never use it.",
    "strategy": "Deploy Jawas into X-wings. What else?",
    "is_light_side": true,
    "is_public": true,
    "cards": [
        { "id": 15, "deck_count": 1, "start_count": 0 },
        { "id": 200, "deck_count": 1, "start_count": 0 },
        { "id": 438, "deck_count": 2, "start_count": 0 },
        { "id": 505, "deck_count": 1, "start_count": 0 }
        ]
}

If an existing deck is being edited, the deck ID is included.

{
    "deck_id": 78,
    "name": "Jawa X-Wings of DOOM",
    "description": "This deck has never lost... because I never use it.",
    "strategy": "Deploy Jawas into X-wings. What else?",
    "is_light_side": true,
    "is_public": true,
    "cards": [
        { "id": 15, "deck_count": 1, "start_count": 0 },
        { "id": 200, "deck_count": 1, "start_count": 0 },
        { "id": 438, "deck_count": 1, "start_count": 0 },
        { "id": 679, "deck_count": 2, "start_count": 0 }
        ]
}

Deck updates use SQL transactions to simplify the process and ensure that the entire update succeeds or fails as a whole.

BEGIN TRANSACTION
UPDATE decks SET ... WHERE deck_id = 78;
DELETE FROM deck_cards WHERE deck_id = 78;
INSERT INTO deck_cards ...;
COMMIT

If the transaction succeeds, it returns status 200; otherwise it returns status 500 and performs a rollback.

Clone this wiki locally