13 API Sudoku
Tim Svensson edited this page 2026-05-27 11:22:22 +00:00

Sudoku API

The sudoku feature uses an external API to generate a playable Sudoku board, The data is fetched on demand and is used to initialize a fully interactive client-sided game. The API returns a single 9x9 which is then transformed into the internal game state.

API Usage

Fetching Data

The Sudoku board is fetched from:

https://sudoku-api.vercel.app/api/dosuku?query={newboard(limit:1){grids{value}}}

The API does not require authentication or parameters.

The request is handled through the custom hook:

useSudokuModal(refreshKey);

Refresh behavior

A new board is fetched whenever refreshKey is changed:

  • Initial → fetch board
  • clicking "New game" → increments refreshKey
  • Modal open → uses latest fetched data.

Response Structure

Data structure

The API returns a JSON object containing a single board

The board data is located at:

newboard.grids[0].value

This value contains a 9x9 array of numbers

Example:

{
  "newboard": {
    "grids": [
      {
        "value": [
          [0, 0, 0, 0, 5, 7, 8, 0, 3],
          [7, 3, 0, 0, 0, 9, 0, 2, 0],
          [0, 5, 8, 0, 3, 1, 7, 6, 0],
          [6, 0, 0, 0, 9, 2, 0, 0, 0],
          [0, 0, 3, 5, 0, 8, 0, 0, 9],
          [0, 9, 5, 0, 0, 3, 0, 7, 2],
          [0, 0, 7, 0, 1, 4, 0, 0, 0],
          [3, 6, 0, 0, 7, 0, 0, 0, 1],
          [0, 0, 0, 0, 2, 0, 0, 3, 7]
        ]
      }
    ]
  }
}

Value Meaning

Value Meaning
0 Empty cell (Player input
1-9 Pre-filled fixed number

Client-sided implementation

Game state structure

Each cell in the internal board is represented as:

{
  value: number,
  notes: Set<number>
}

Where:

  • value = current number in the cell

  • notes = marking values.

Validation rules

The application also validates the board by checking:

  • duplicate values in rows
  • duplicate values in columns
  • duplicate values in an 3x3 area

Additional APIs

Send a request to get the solution of the grid only:

Send a request to get the difficulty:

Get multiple results by changing the limit: