Create Link
POST
https://api.example.com/api/link
Requires authentication:
x-api-key: YOUR_API_KEY
Creates a new shortened link. The link name and destination URL must be supplied in the request body. The link is attributed to API as its creator.
Headers
-
x-api-keystring requiredYour API authentication key.Example:YOUR_API_KEY
Body parameters
-
namestring requiredThe unique name to assign to the shortened link.Example:google -
urlstring requiredThe destination URL for the shortened link.Example:https://google.com
Responses
- 201Created
- 409Conflict
Request
curl -X POST 'https://api.example.com/api/link' \
-H 'x-api-key: YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"name": "google",
"url": "https://google.com"
}'
const response = await fetch('https://api.example.com/api/link', {
method: 'POST',
headers: {
'x-api-key': 'YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"name": "google",
"url": "https://google.com"
}),
});
const data = await response.json();
console.log(data);
import requests
response = requests.post(
"https://api.example.com/api/link",
headers={
"x-api-key": "YOUR_API_KEY",
"Content-Type": "application/json",
},
json={
"name": "google",
"url": "https://google.com"
},
)
print(response.json())
<?php
$ch = curl_init('https://api.example.com/api/link');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'x-api-key: YOUR_API_KEY',
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => '{
"name": "google",
"url": "https://google.com"
}',
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
print_r($response);
Response
Created
{
"id": 1,
"name": "google",
"url": "https://google.com",
"count": 0,
"creator": "API",
"creatorID": "0",
"createdAt": 1795400000000
}
Conflict
{
"msg": "A link with that name already exists."
}