Skip to content

Instantly share code, notes, and snippets.

@handhikadj
Created June 1, 2019 21:20
Show Gist options
  • Save handhikadj/c66faa9a1572323a03a712cd37dc909d to your computer and use it in GitHub Desktop.
Save handhikadj/c66faa9a1572323a03a712cd37dc909d to your computer and use it in GitHub Desktop.
<?php
use GuzzleHttp\Exception\ConnectException;
require_once("vendor/autoload.php");
/* Start to develop here. Best regards https://php-download.com/ */
function connectMyApi() {
$nama = $_GET['namaku'];
$appPath = "192.168.0.2/laravel-api-passport/public";
try {
$client = new GuzzleHttp\Client();
$clientPost = $client->post("{$appPath}/posttodb", [
'body' => [
'name_product' => $nama
]
]);
return json_encode(['data' => $clientPost]);
} catch (ConnectException $e) {
return json_encode(['data' => $e->getMessage()]);
}
}
echo connectMyApi();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment