Code Monkey home page Code Monkey logo

url-shortener-axum-askama-htmx's Introduction

Shortify - A Rust/Axum URL Shortener App


A Full Stack Url Shortener App using Rust's Axum framework + </>HTMX & Askama.

GitHub License Static Badge Static Badge


๐Ÿค” What Stack have we used?

In the implementation of this application we have used the following technologies:


Note

The use of </>htmx allows behavior similar to that of a SPA, without page reloads when switching from one route to another or when making requests (via AJAX) to the backend. Likewise, the _hyperscript library allows you to add some dynamic features to the frontend in a very easy way.


๐Ÿ–ผ๏ธ Screenshots:

Home page showing button to copy shortened URL and loading indicator & error handling pages:

ย ย ย ย 


๐Ÿ‘จโ€๐Ÿš€ Getting Started

How to build for production

Besides the obvious prerequisite of having Rust on your machine, you must have cargo watch installed for hot reloading when editing code.

Since we use the PostgreSQL database from a Docker container, it is necessary to have the latter also installed and execute this command in the project folder:

$ docker compose up -d

These other commands will also be useful to manage the database from its container:

$ docker start shortify-db # start container
$ docker stop shortify-db # stop container
$ docker exec -it shorturl-rs psql -U enrique -W shorturl # (pass: emarifer) access the database

You will also need to have the sqlx CLI installed (sqlx-cli, install it with the command cargo install sqlx-cli) to be able to do the migrations to the database. Run the following command in the migrations folder:

$ sqlx migrate run # sqlx migrate revert (to reverse the migration)

Before compiling the binary, you will have to regenerate the CSS. To do this, go to the tailwind folder and run the following (you must have Node.js installed):

$ cd tailwind && npm run build-css-prod

Build the binary file and run it with the command:

$ cargo build --release && ./target/release/shorturl-rs # Ctrl + C to stop the application

Build for development

If what you want is to edit the code, it will be more like activating hot reload:

$ cargo watch -x run -w src -w assets -w templates

โš ๏ธ Since the docker compose up -d command creates a volume (as a hidden folder) in the project folder to store the data of the Postgres database and that folder requires system administrator permissions, the cargo command watch -x run would return an error. Therefore, we only "watch" the src, assets and templates folders.

If you also want to modify the CSS of the templates, it will be useful to activate the watch mode of Tailwindcss, executing the command inside the tailwind folder (you need to have Node.js installed):

$ npm run watch-css # minify for production: npm run build-css-prod

Happy coding ๐Ÿ˜€!!

url-shortener-axum-askama-htmx's People

Contributors

emarifer avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

jmonts

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.