[call-me] - add API examples

This commit is contained in:
Miroslav Pejic
2024-12-07 23:36:35 +01:00
parent c0e3a84dd5
commit 9f70b20f0f
4 changed files with 58 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
'use strict';
const $url = 'https://localhost:8000/api/v1/users';
const authorization = 'call_me_api_key_secret';
fetch(url, {
method: 'GET',
headers: {
Authorization: authorization,
'Content-Type': 'application/json',
},
})
.then((response) => response.json()) // Parse the JSON response
.then((data) => console.log(data)) // Log the data
.catch((error) => console.error('Error:', error)); // Handle errors
+19
View File
@@ -0,0 +1,19 @@
<?php
$url = "http://localhost:8000/api/v1/users";
$authorization = "call_me_api_key_secret";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"authorization: $authorization",
"Content-Type: application/json"
));
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
+14
View File
@@ -0,0 +1,14 @@
import requests # pip3 install requests
url = "http://localhost:8000/api/v1/users"
authorization = "call_me_api_key_secret"
headers = {
'Authorization': authorization,
'Content-Type': 'application/json'
}
response = requests.get(url, headers=headers)
print(response.json())
+9
View File
@@ -0,0 +1,9 @@
#!/bin/bash
url = "http://localhost:8000/api/v1/users";
authorization="call_me_api_key_secret"
response=$(curl -s -X GET "$url" -H "Authorization: $authorization" -H "Content-Type: application/json")
echo "$response"