URL Shortener API Documentation

Introduction

This documentation provides information on how to use the URL shortener API. The API allows you to shorten URLs, generate API tokens, and retrieve analytics for your shortened links.

Endpoints

/api/shorten

Shortens a URL using the API.

                POST /api/shorten
                Headers:
                    Authorization: {api_token}
                Body:
                    {
                        "url": "http://s1d.me/",
                        "length": 6,
                        "allow_numbers": true,
                        "allow_uppercase": true,
                        "allow_lowercase": true,
                        "expiry_time": "2023-12-31 23:59:59"
                    }
                Response:
                    {
                        "short_code": "abc123"
                    }
            

Example using curl

                curl -X POST https://s1d.me/api/shorten \
                    -H "Authorization: your_api_token" \
                    -H "Content-Type: application/json" \
                    -d '{
                        "url": "http://s1d.me/",
                        "length": 6,
                        "allow_numbers": true,
                        "allow_uppercase": true,
                        "allow_lowercase": true,
                        "expiry_time": "2023-12-31 23:59:59"
                    }'
            

Example using Python

                import requests

                url = "https://s1d.me/api/shorten"
                headers = {
                    "Authorization": "your_api_token",
                    "Content-Type": "application/json"
                }
                data = {
                    "url": "http://s1d.me/",
                    "length": 6,
                    "allow_numbers": True,
                    "allow_uppercase": True,
                    "allow_lowercase": True,
                    "expiry_time": "2023-12-31 23:59:59"
                }

                response = requests.post(url, headers=headers, json=data)
                print(response.json())
            

/api/analytics

Gets analytics for the API token.

                GET /api/analytics
                Headers:
                    Authorization: {api_token}
                Response:
                    {
                        "link_count": 10,
                        "click_count": 50,
                        "links": [
                            {
                                "short_code": "abc123",
                                "original_url": "http://s1d.me/",
                                "click_count": 5,
                                "expiry_time": "2023-12-31 23:59:59"
                            },
                            ...
                        ]
                    }
            

Example using curl

                curl -X GET https://s1d.me/api/analytics \
                    -H "Authorization: your_api_token"
            

Example using Python

                import requests

                url = "https://s1d.me/api/analytics"
                headers = {
                    "Authorization": "your_api_token"
                }

                response = requests.get(url, headers=headers)
                print(response.json())
            

/api/reset_api_token

Resets the API token for the authenticated user.

                POST /api/reset_api_token
                Headers:
                    Authorization: {api_token}
                Response:
                    {
                        "token": "new_api_token"
                    }
            

Example using curl

                curl -X POST https://s1d.me/api/reset_api_token \
                    -H "Authorization: your_api_token"
            

Example using Python

                import requests

                url = "https://s1d.me/api/reset_api_token"
                headers = {
                    "Authorization": "your_api_token"
                }

                response = requests.post(url, headers=headers)
                print(response.json())
            

/api/link_analytics/{short_code}

Gets analytics for a specific shortened link.

                GET /api/link_analytics/{short_code}
                Headers:
                    Authorization: {api_token}
                Response:
                    {
                        "short_code": "abc123",
                        "original_url": "http://s1d.me/",
                        "click_count": 5,
                        "expiry_time": "2023-12-31 23:59:59"
                    }
            

Example using curl

                curl -X GET https://s1d.me/api/link_analytics/abc123 \
                    -H "Authorization: your_api_token"
            

Example using Python

                import requests

                url = "https://s1d.me/api/link_analytics/abc123"
                headers = {
                    "Authorization": "your_api_token"
                }

                response = requests.get(url, headers=headers)
                print(response.json())
            

Rate Limiting

The API endpoints have rate limits to prevent abuse:

Authentication

Most API endpoints require authentication. You need to include the API token in the Authorization header of your requests.

            Authorization: {api_token}
        

Error Handling

The API returns standard HTTP status codes to indicate the success or failure of the request. Here are some common status codes:

Examples

Shorten a URL

Example using curl

            curl -X POST https://s1d.me/api/shorten \
                -H "Authorization: your_api_token" \
                -H "Content-Type: application/json" \
                -d '{
                    "url": "http://s1d.me/",
                    "length": 6,
                    "allow_numbers": true,
                    "allow_uppercase": true,
                    "allow_lowercase": true,
                    "expiry_time": "2023-12-31 23:59:59"
                }'
        

Example using Python

            import requests

            url = "https://s1d.me/api/shorten"
            headers = {
                "Authorization": "your_api_token",
                "Content-Type": "application/json"
            }
            data = {
                "url": "http://s1d.me/",
                "length": 6,
                "allow_numbers": True,
                "allow_uppercase": True,
                "allow_lowercase": True,
                "expiry_time": "2023-12-31 23:59:59"
            }

            response = requests.post(url, headers=headers, json=data)
            print(response.json())
        

Get Analytics

Example using curl

            curl -X GET https://s1d.me/api/analytics \
                -H "Authorization: your_api_token"
        

Example using Python

            import requests

            url = "https://s1d.me/api/analytics"
            headers = {
                "Authorization": "your_api_token"
            }

            response = requests.get(url, headers=headers)
            print(response.json())
        

Reset API Token

Example using curl

            curl -X POST https://s1d.me/api/reset_api_token \
                -H "Authorization: your_api_token"
        

Example using Python

            import requests

            url = "https://s1d.me/api/reset_api_token"
            headers = {
                "Authorization": "your_api_token"
            }

            response = requests.post(url, headers=headers)
            print(response.json())
        

Get Link Analytics

Example using curl

            curl -X GET https://s1d.me/api/link_analytics/abc123 \
                -H "Authorization: your_api_token"
        

Example using Python

            import requests

            url = "https://s1d.me/api/link_analytics/abc123"
            headers = {
                "Authorization": "your_api_token"
            }

            response = requests.get(url, headers=headers)
            print(response.json())
        

Contact

If you have any questions or need further assistance, please contact me at sarthaksidhantisopolice@gmail.com