Coder Social home page Coder Social logo

url-shortener's Introduction

FastAPI-based URL Shortener

This repository is DEPRECATED! Use url-shortener2 instead which is a re-written version of this repositry with Users and Authentication/Authorization baked in.

This is based on an original tutorial from Real Python which I definitely recommend checking out for a decent example of a non-trivial FastAPI app.

Added Features

  • Refactored the code so that each 'group' of Routes is in its own file, and moved some utility & error functions to a dedicated module. This makes the project much cleaner and easier to understand. Add tags to each group for better documentation.
  • /list (GET) route to return a list of all the URL's in the database along with their target.
  • /{url_key}/peek (GET) route to show the target url of the specified url_key, without actually redirecting there. Allows users or front-end client to check the URL before visiting.
  • /admin/{secret_key} (PATCH) route to change the target URL of a link identified by the secret_key. The body of the request needs to have the target_url property containing the new URL which must be a valid URL
  • The Root Path ("/") will return a short HTML template if viewed in a Web Browser, JSON otherwise.
  • Choose either the default SQLite database or Postgresql from the .env file.
  • The URL Key is case-sensitive, so added lowercase letters to the mix for extra availability. Now the key will randomly include upper, lower and numbers.

Planned Features

Non-exhaustive list of planned additions, in no specific order.

  • Option to add a delay to the redirect, showing the exact target URL and giving the option to Cancel.
  • User-friendly Front-end (probably in React) for adding and editing URLs.
  • Protected ability to purge all is_active: false URLs
  • Custom URL key - allow user to use their own key instead of the autogenerated one.
  • Add Users and Auth, replace the current 'SECRET_KEY' method of dealing with ownership.

Configuration

This is done using the .env file in the root folder. See .env.example for details:

ENV_NAME="Development"
BASE_URL="http://127.0.0.1:8000"

# Comment/Uncomment your choice of database. If Postgreql, the other 5 variables
# below need to be also filled. Will default to SQLite if none selected.
DB_BACKEND="sqlite"
# DB_BACKEND="postgresql"

# location and name of SQLite database, if used.
DB_URL="sqlite:///./shortener.db"

# Postgresql stuff if selected above.
DB_NAME="<YOUR_DB_NAME>"
DB_ADDRESS="<YOUR_DB_ADDRESS>"
DB_PORT="<YOUR_DB_PORT>"
DB_USER="<YOUR_DB_USER>"
DB_PW="<YOUR_DB_PASSWORD>"

Development

Install the required dependency packages :

pip install -r requirements.txt

Run a local development server from the project root using Uvicorn :

uvicorn shortener_app.main:app --reload

Access the API at http://localhost:8000

See the API Docs at http://localhost:8000/docs or http://localhost:8000/redoc for a list of the active endpoints

url-shortener's People

Contributors

seapagan avatar

Stargazers

 avatar Madjar Evan avatar

Watchers

 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.