4
Resources - Opensource
admin edited this page 2026-01-19 09:17:41 -05:00
<script src="https://unpkg.com/maplibre-gl@^5.16.0/dist/maplibre-gl.js"></script>
<link href="https://unpkg.com/maplibre-gl@^5.16.0/dist/maplibre-gl.css" rel="stylesheet" />
PHP API Development via SLIM
Tailwind(https://tailwindcss.com/docs/installation/using-vite)
<script src="https://cdn.tailwindcss.com"></script>
PHP couchdb integration
<?php
require "vendor/autoload.php";
// Connect to the CouchDB server
$server = new PHPCouchDB\Server(["url" => "http://localhost:5984"]);
// Use a specific database, creating it if it doesn't exist
$test_db = $server->useDb(["name" => "test", "create_if_not_exists" => true]);
// Create a new document
$doc_data = ["name" => "Alice", "interests" => ["eating", "wondering"]];
$new_doc = $test_db->create($doc_data);
// Inspect the document returned by the server
print_r($new_doc);
// Update the document
$new_doc->friends[] = "Cheshire Cat";
$updated_doc = $new_doc->update();
// Delete the document
$updated_doc->delete();
?>
Direct calls to via CURL
<?php
$ch = curl_init();
$url = "http://localhost:5984/mydb/my_doc_id";
// Retrieve a document (GET request)
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo "Document retrieved: " . $response;
// To create/update a document (PUT request)
$data = json_encode(["_id" => "my_doc_id", "field1" => "value1", "field2" => "value2"]);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo "Document created/updated: " . $response;
?>