Skip to content

jakemingolla/url-shortener

Repository files navigation

url-shortener

Features

  • API Documentation: Integrated Swagger UI for easy exploration and testing of API endpoints.
  • Redirect Management: Create, update, and delete URL redirects with ease.
  • Automated Testing: Comprehensive test suites ensure the reliability and stability of the application.
  • Continuous Integration: GitHub Actions workflow for linting, testing, and maintaining code quality.

Getting Started

Prerequisites

  • Bun: Ensure you have Bun installed. You can install it using the following command:

    curl https://bun.sh/install | bash

Installation

  1. Clone the Repository

    git clone /~https://github.com/jakemingolla/url-shortener.git
    cd url-shortener
  2. Install Dependencies

    bun install
  3. Environment Variables

    Create a .env file in the root directory and include the necessary environment variables as needed.

Running the Application

Start the server using docker compose:

bun run start

The server will be listening on http://localhost:3000.

To get logs of the application (or database):

bun run logs:app
bun run logs:postgres

Example

  • Create Redirect

    curl \
      -X POST \
      -H "Content-Type: application/json" \
      --data '{ "destination": "http://stackoverflow.com " }' \
      http://localhost:3000/api/v1/redirects
    
    >> {"id":"b2c3a275-5b2e-44cb-9f0c-aed5a1ca6f4a"}
  • Use Redirect

    curl -v localhost:3000/r/b2c3a275-5b2e-44cb-9f0c-aed5a1ca6f4a
    ...
    < HTTP/1.1 302 Found
    < Location: http://stackoverflow.com
  • View Redirect Details

      curl \
        -X GET \
        -H "Content-Type: application/json" \
        http://localhost:3000/api/v1/redirects/b2c3a275-5b2e-44cb-9f0c-aed5a1ca6f4a
    
      {
        "id": "b2c3a275-5b2e-44cb-9f0c-aed5a1ca6f4a",
        "destination": "http://stackoverflow.com ",
        "hits": 1,
        "createdAt": "2024-12-30T16:39:41.515Z",
        "updatedAt": "2024-12-30T16:40:58.357Z",
        "deletedAt": null
      }

API Documentation

Access the Swagger UI for interactive API documentation at http://localhost:3000/swagger.

Seeds

The database seeds add baseline redirects into Postgres for local development and testing.

  • Run Seeds
    bun run seed:up
  • Create Seeds
    bun run seed:make <name>
  • Reseting Database
    bun run reset

Testing

Note

You must make sure you have all up-to-date seeds created before running tests.

Run the test suites using Bun:

bun test

Database Migrations

Manage your database schema with the provided migration scripts.

  • Run Migrations

    bun run migration:up
  • Rollback Migrations

    bun run migration:down
  • Create New Migration

    bun run migration:make <name>
  • Update src/db/types.d.ts

    This will adjust the TypeScript types to match what's in the current local database

    bun run generate-types

Contributing

Contributions are welcome! Please follow these steps to contribute:

  1. Fork the repository.
  2. Create a new branch for your feature or bugfix.
  3. Commit your changes with clear and descriptive messages.
  4. Push to your fork and create a pull request.

License

This project is licensed under the MIT License.


This project was created using bun init in bun v1.1.42. Bun is a fast all-in-one JavaScript runtime.

About

REST API for managing URL short links

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published