An API-based permalink redirector/URL shortener. https://href.vlw.se/demo
Find a file
2025-03-11 10:19:45 +01:00
endpoints/href fix: classname for href DELETE endpoint 2025-02-09 10:12:52 +01:00
public initial commit 2025-02-09 09:31:11 +01:00
reflect@097a0bf777 feat: add install script and Reflect submodule 2025-03-11 10:19:45 +01:00
src initial commit 2025-02-09 09:31:11 +01:00
.env.example.ini fix: add example ini file 2025-02-09 09:50:14 +01:00
.gitignore initial commit 2025-02-09 09:31:11 +01:00
.gitmodules feat: add install script and Reflect submodule 2025-03-11 10:19:45 +01:00
composer.json initial commit 2025-02-09 09:31:11 +01:00
composer.lock initial commit 2025-02-09 09:31:11 +01:00
install.sh feat: add install script and Reflect submodule 2025-03-11 10:19:45 +01:00
LICENSE initial commit 2025-02-09 09:31:11 +01:00
README.md doc: create README.md 2025-02-09 11:15:38 +00:00

HREF

An API-based link redirector/URL shortener using my Reflect API framework.

Create permalinks to stuff on the internet with an easy-to-use API interface.

Example redirection

Installation

This program requires PHP 8.0+ (with composer) and MariaDB to be installed.

1. Clone this repo

Let's start by cloning this repo - preferably to a non-public directory.

git clone https://codeberg.org/vlw/href --depth 1

Point ALL requests from your configured webserver to the public/index.php file in this repository. Routing is handled by this program.

2. Download and import the sample database

Download the SQL file from the releases page and import it into an empty MariaDB database.

Example

mysql href < href.sql

3. Install Reflect

Download and install the Reflect API framework and follow the installation instructions for that.

Point the reflects endpoints environment variable to the root of the directory you cloned before. And the database variable to the database you imported the SQL file into before.

Example

# Reflect .env.ini
endpoints = "/var/www/href"
# ...
mysql_db = "href"

4. Install dependencies

Install dependencies for this program with composer

composer install --optimize-autoloader

5. Create environment variables file

Copy the .env.example.ini file from the root of the repository directory to a file called .env.ini.

Set your environment variables in this file.

Manage permalinks

GET /href?id=<id>

Make a GET request to the /href endpoint passing a permalink id as a parameter. The id parameter is the same as the database column id, and it's also the pathname that you would use when navigating to a permalink.

POST /href
# Request body - Content-Type: application/json
{
    # This will be the pathname/permalink you wish to redirect from
    "id":      "example",
    # This will be the destination URL you wish to redirect to
    "href":    "https://example.com",
    # This OPTIONAL parameter can be used to set a comment for the permalink
    "comment": "An example permalink"
}
PATCH /href?id=<id>

A search parameters with the id of the permalink you wish to update is required.

This method uses the same request body structure as POST except all paramers are optional, and parameters present in the request body when the PATHC request is sent; will be updated.

DELETE /href?id=<id>

A serch paramter with the id of the permalink you wish to delete is required.

When a DELETE request is made to an id, that entry is completely deleted