This page provides documentation for the URL shortener API.
Endpoint: /api/v1/shorten
Method: POST
Request Body:
{"url": "https://example.com"}
Response:
{"shortUrl": "https://0s.lv/xxxx","cid": 1}
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
func main() {
apiURL := "https://0s.lv/api/v1/shorten"
data := map[string]string{"url": "https://example.com"}
jsonData, _ := json.Marshal(data)
resp, err := http.Post(apiURL, "application/json", bytes.NewBuffer(jsonData))
if err != nil {
fmt.Println("Error:", err)
return
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
}
<?php
$apiUrl = 'https://0s.lv/api/v1/shorten';
$data = ['url' => 'https://example.com'];
$options = [
'http' => [
'header' => "Content-type: application/json\r\n",
'method' => 'POST',
'content' => json_encode($data),
],
];
$context = stream_context_create($options);
$result = file_get_contents($apiUrl, false, $context);
echo $result;
?>
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class ShortenClient {
public static void main(String[] args) throws Exception {
String apiUrl = "https://0s.lv/api/v1/shorten";
String json = "{\"url\":\"https://example.com\"}";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(apiUrl))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
const fetch = require('node-fetch');
const apiUrl = 'https://0s.lv/api/v1/shorten';
const data = { url: 'https://example.com' };
fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
})
.then(res => res.json())
.then(json => console.log(json));