Code Monkey home page Code Monkey logo

yaus's Introduction

yaus

Yet Another URL Shortener in Rust.

YAUS was inspired by this comment on HN. I had wanted to write a web service in Rust and thought it would be a simple exercise to demonstrate Rust's strengths in speed and safety.

It is implemented using the Iron framework with SQLite for storing the urls. The site has NGINX sitting in front as a reverse proxy as well.

Implementation

This app uses Iron's persistent crate to share the SQLite connection between the handlers. The pooling is provided by r2d2.

To generate the short URL identifier it uses the first seven bytes from the SHA-2 hash of the original URL. Again, I may have overlooked any issues with this, but the chance of collision is unlikely.

API

To shorten a URL you can hit the shorten endpoint:

curl https://yaus.pw/shorten?url=[1]

[1]: A valid URL

Responses:

  • 200 The shortened URL exists and has been returned.
  • 201 The new shortened URL has been created and returned.
  • 400 Invalid request, see the error message.

To retrieve the shortened URL:

curl https://yaus.pw/[1]

[1]: A valid short identifier

Responses:

  • 301 The URL has been redirected.
  • 404 The identifier has not been found.

Future Goals

  • Share the necessary packages used to build and run the service
  • Make the app configurable
  • Share NGINX configuration and how to install a certificate with LetsEncrypt
  • Add an HTML form to use through a browser
  • Add expiration to the links to keep the database from growing too big

License

MIT

yaus's People

Contributors

gsquire 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.