Giter Club home page Giter Club logo

url-shortener's Introduction

url-shortener

License: Unlicense

Description

This is a simple URL shortener project built in Java. It uses Javalin to handle REST requests. It stores information about URLs in a database. You can currently choose between SQLite, MySQL and MongoDB.

There is also a frontend that is made with Svelte.

Usage

Users are required to have an account before they can create urls. They will receive an JWT token after logging in.

Register

curl --location 'http://localhost:8020/api/auth/register' \
--header 'Content-Type: application/json' \
--data '{"username": "YOUR_NAME", "password": "YOUR_PASSWORD"}'

Login

curl --location 'http://localhost:8020/api/auth/login' \
--header 'Content-Type: application/json' \
--data '{"username": "YOUR_NAME", "password": "YOUR_PASSWORD"}'

Shortening a URL

This command sends a POST request to the /api/create endpoint with the original URL as JSON data. The server will generate a short URL for the provided URL.

curl --location 'http://localhost:8020/api/create' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR_TOKEN_HERE' \
--data '{"url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ"}'

The response will look like this

{"url":"tQYC5b"}

Retrieving URL Information

This command sends a GET request to the /api/stats/{code} endpoint, where {code} represents the short URL code. The server will return information about the URL, including the original URL and the number of redirects. Make sure to replace tQYC5b with the actual short URL code.

curl --location 'http://localhost:8020/api/stats/tQYC5b'

The response will look like this

{"original_url":"https://www.youtube.com/watch?v=dQw4w9WgXcQ","redirects":0,"shortened_url":"tQYC5b"}

Accessing Shortened URLs

Once a URL is shortened, you can access it using the shortened URL, for example:

http://localhost:8020/tQYC5b

Frontend

To launch the frontend run the following command in the frontend directory

npm run dev -- --open

Screenshots

Home

Stats

Login

License

This project is licensed under the Unlicense

url-shortener's People

Contributors

janbnz avatar

Watchers

 avatar

url-shortener's Issues

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.