Skip to content

cjmellor/atarim-tech-test

Repository files navigation

URL Shortener

Features

  • URL encoding: Convert long URLs into short ones
  • URL decoding: Retrieves original URLs from shortened versions
  • Input validation: Ensures URLs are valid and properly formatted
  • In-memory storage: Stores URL mappings temporarily
  • RESTful API: JSON-based endpoints
  • Tests: Full test coverage

Technical Highlights

  • SOLID Principles: The codebase adheres to SOLID principles for maintainability and extensibility
    • Single Responsibility: Each class has a clear, focused purpose
    • Open/Closed: The service is open for extension but closed for modification
    • Liskov Substitution: Interfaces ensure consistent behaviour across implementations
    • Interface Segregation: Focused interfaces for specific responsibilities
    • Dependency Inversion: High-level modules depend on abstractions, not concretions
  • Clean Architecture: Separation of concerns through controllers, services, and contracts
  • Validation: Dedicated request class for consistent input validation
  • API Responses: Standardised JSON responses with appropriate HTTP status codes
  • Testing: Comprehensive test coverage using PHPUnit

Installation

  1. Clone the repository:

    git clone https://github.com/cjmellor/atarim-tech-test.git
    cd atarim-tech-test
  2. Install dependencies:

    composer install
  3. Copy the environment file:

    cp .env.example .env
  4. Generate application key:

    php artisan key:generate
  5. Configure the base URL in .env (can be anything):

    URLSHORTENER_BASE_URL=http://short.est/ 
  6. Run the development server:

    php artisan serve

API Endpoints

Encode URL

POST /api/encode

Request:

{
    "url": "https://www.example.com/some/long/path"
}

Response:

{
    "short_url": "http://short.est/abc123"
}

Decode URL

POST /api/decode

Request:

{
    "url": "http://short.est/abc123"
}

Response:

{
    "original_url": "https://www.example.com/some/long/path"
}

Running Tests

To run the test suite:

./vendor/bin/phpunit

(I used an LLM to make this more presentable)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Languages