GithubHelp home page GithubHelp logo

lil's Introduction

Lil

Simple URL shortener based on Go.

API

Redirect

GET /<id> - Redirects to target URL.

Redirect page

GET /p/<id> - HTML page which redirects to target url. Page additionally renders OpenGraph tags specified while creating short url. Useful for sharing previewable link in social media sites.

Create a short url

POST /api/new - Create a random short url for given url, accepts JSON post body.

Params

  • url - Target url to redirect.
  • title - Page title used in paged redirect.
  • og_tags - List of Open graph tags to be used in paged redirect.
    • property - Open graph property tag
    • content - Open graph content tag

Response

Response returns short uri ID, redirect url and page redirect url.

{
    "data": {
        "id": "<id>",
        "url": "http://localhost/<id>",
        "page": "http://localhost/p/<id>"
    }
}

Get redirect links

GET /api/<id> - Get redirect links for given short uri.

Response

Response returns short uri ID, redirect url and page redirect url.

{
    "data": {
        "id": "<id>",
        "url": "http://localhost/<id>",
        "page": "http://localhost/p/<id>"
    }
}

Delete a short url

DELETE /api/<id> - Delete a give short url.

Response

{
    "data": true
}

Examples

Create a short url

# Request
curl -X "POST" "http://localhost:8085/api/new" \
     -H 'Content-Type: text/plain; charset=utf-8' \
     -d $'{
    "url": "https://zerodha.com",
    "title": "Zerodha",
    "og_tags": [
        {"property": "og:image", "content": "https://zerodha.com/static/images/kite-dashboard.png"}
    ]
}'

# Response
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8

{
    "data": {
        "id": "72p9abOM",
        "url": "http://localhost:8085/72p9abOM",
        "page": "http://localhost:8085/p/72p9abOM"
    }
}

Direct redirect

# Request
curl http://localhost:8085/72p9abOM

# Response
HTTP/1.1 301 Moved Permanently
Content-Type: text/html; charset=utf-8
Location: https://zerodha.com

<a href="https://zerodha.com">Moved Permanently</a>.

Page redirect

# Page redirect which renders additional open graph data.
curl http://localhost:8085/p/72p9abOM

# Response
HTTP/1.1 200 OK
Date: Thu, 18 Jul 2019 08:14:03 GMT

<html prefix="og: http://ogp.me/ns#">
<head>
    <title>Zerodha</title>
    <meta property="og:image" content="https://zerodha.com/static/images/kite-dashboard.png" />
    <script >
        window.location.replace("https:\/\/zerodha.com");
    </script>
</head>
</html>

Get redirect links

# Request
curl "http://localhost:8085/api/72p9abOM"

# Response
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8

{
    "data": {
        "id": "72p9abOM",
        "url": "http://localhost:8085/72p9abOM",
        "page": "http://localhost:8085/p/72p9abOM"
    }
}

Delete a short url

# Request
curl -X "DELETE" "http://localhost:8085/api/72p9abOM"

# Response
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8

{
    "data": true
}

Backend store

Currently Redis is the only backend store available but new stores can be easily added by implementing store interface, for example here is the Redis store implementation.

TODO

  • Basic auth for create and delete APIs. Currently this can be implemented behind reverse proxy like Nginx or API gateways like Kong, AWS API gateway.
  • Custom path for short URLs instead of random generated paths.
  • Redirect stats.

lil's People

Contributors

vividvilla avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.