myv@API

SUDOKU All-Purpose PRO API

 

 

Code examples

At https://rapidapi.com/myvatAPI/api/sudoku-all-purpose-pro/endpoints/, you'll find examples in 19 different programming languages to access this API, including popular languages like Node.js, JavaScript and Python. In following basic examples we focus on PHP and retrieve the API using cURL.

 

Example 1: Basic usage

Let's create a Sudoku with 35 given digits and choose JPG as output format. Since we have not specified the width of the image, the colors and the compression, default values are used. The required query is: ?create=35&output=jpg

  <?php
//example 1: basic usage
//source: https://myv.at/api/sudoku/code-examples/

//start cURL request
$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => "https://sudoku-all-purpose-pro.p.rapidapi.com/sudoku?create=35&output=jpg",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_HTTPHEADER => [
    "x-rapidapi-host: sudoku-all-purpose-pro.p.rapidapi.com",
    "x-rapidapi-key: SIGN-UP-FOR-KEY"
    ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);

//exit on all cURL errors
if ($err) {
    echo "cURL Error #:" . $err;
    exit;
}
//end cURL request 

   
//return JSON
echo $response;
?>

This is the returned answer: View example JSON file. As you can see the JSON file contains the encoded JPG image. But how can we use this image?

 

Example 2: Decode image data from JSON and save it

Again we create an Sudoku with 35 given digits and choose JPG as output format, but now with some additional code lines for decoding and saving.

  <?php
//example 2: decode image data from JSON and save it
//source: https://myv.at/api/sudoku/code-examples/

//start cURL request
$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => "https://sudoku-all-purpose-pro.p.rapidapi.com/sudoku?create=35&output=jpg",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_HTTPHEADER => [
    "x-rapidapi-host: sudoku-all-purpose-pro.p.rapidapi.com",
    "x-rapidapi-key: SIGN-UP-FOR-KEY"
    ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);

//exit on all cURL errors
if ($err) {
    echo "cURL Error #:" . $err;
    exit;
}
//end cURL request 


//convert returned JSON object into an associative array
$array = json_decode($response, true);

//access image data
if (isset($array["output"]["base64_data"])) { //check if "base64_data" is really available	
    $image_data = $array["output"]["base64_data"];
}else{
    echo "Did you set OUTPUT? Seems that only RAW is available.\n";
    //return JSON
    echo $response;
    exit;
}

//decode image data
$image = base64_decode($image_data);

//save image
$fp = fopen("new_sudoku.jpg", 'w');
fwrite($fp, $image);
fclose($fp);

//return JSON to get also RAW data for further processing after generating the image
echo $response;
?>

Now you can find the created image in the specified place.

 

Example 3: Decode SVG data from JSON and save it

Now we create a medium Sudoku and choose SVG as output format, decode it and don't forget to save it with .svg file extension.

  <?php
//example 3: decode SVG data from JSON and save it
//source: https://myv.at/api/sudoku/code-examples/

//start cURL request
$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => "https://sudoku-all-purpose-pro.p.rapidapi.com/sudoku?create=medium&output=svg",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_HTTPHEADER => [
    "x-rapidapi-host: sudoku-all-purpose-pro.p.rapidapi.com",
    "x-rapidapi-key: SIGN-UP-FOR-KEY"
    ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);

//exit on all cURL errors
if ($err) {
    echo "cURL Error #:" . $err;
    exit;
}
//end cURL request 


//convert returned JSON object into an associative array
$array = json_decode($response, true);

//access image data
if (isset($array["output"]["base64_data"])) { //check if "base64_data" is really available	
    $image_data = $array["output"]["base64_data"];
}else{
    echo "Did you set OUTPUT? Seems that only RAW is available.\n";
    //return JSON
    echo $response;
    exit;
}

//decode image data
$image = base64_decode($image_data);

//save SVG as .svg
$fp = fopen("new_sudoku.svg", 'w');
fwrite($fp, $image);
fclose($fp);

//return JSON to get also RAW data for further processing after generating the image
echo $response;
?>

Now you have a SVG file and also the RAW data which gives you the ability to solve the generated Sudoku with another API call.

 

Example 4: Use a created HTML file and add some CSS

Like in example 3 but now create a html output with ?create=35&output=html, decode it and save it as file. Use the html data and add some css.

  <!doctype html>
<!-- example 4: HTML, CSS -->
<!-- source: https://myv.at/api/sudoku/code-examples/ -->
<head>
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<meta charset="utf-8">
<title>Sudoku HTML/CSS Example</title>
</head>
<style>
.wrapper {
	max-width : 500px;
}
table {
	border-collapse : collapse;
	width : 100%;
	font-family : 'Roboto Mono', monospace;
	font-weight : 400;
	font-size : 42px;
}
colgroup, tbody {
	border : #222 solid 2px;
}
td {
	border : #999 solid 1px;
	width : 2em;
	text-align : center;
	padding : 0;
	position : relative;
}
td:after {
	content : '';
	display : block;
	margin-top : 100%;
}
td span {
	position : absolute;
	top : 0;
	bottom : 5px;
	left : 0;
	right : 0;
	width : 100%;
	height : 100%;
	justify-content : center;
	display : flex;
	align-items : center;
}
.bg1 {
	background : #BED1F8;
}
.bg2 {
	background : #EBF1FD;
}
</style>
</head>
<body>
<div class="wrapper"> 
  
  <!-- start sudoku html -->
  
  	<!-- insert generated html from JSON here -->
  
  <!-- end sudoku html --> 
  
</div>
</body>
</html>

That's nice! And responsive! And you have full control of colors and the look and feel!

 

Great! That was easy!

There's no more to know to call this API.
Be sure to have also a look at the documentation and the FAQs.

Something missing?

Found a bug? Need something special? Tell us at: sudoku@myv.at
We'll always be there for you, no matter what.

 

 

 

 

 

Example Sudoku

Used query: ?create&output=jpg&quality=85

 

 

 

NEWS:

2021-03-19 - SUDOKU All-Purpose PRO API closed beta version released.

by myvasco.com · legal notice