https://github.com/thekid/shorturl
URL Shortener service
https://github.com/thekid/shorturl
json mysql php7 php8 rest-api shorturl xp-framework
Last synced: about 1 month ago
JSON representation
URL Shortener service
- Host: GitHub
- URL: https://github.com/thekid/shorturl
- Owner: thekid
- Created: 2016-08-14T10:29:27.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2023-10-01T07:46:12.000Z (over 2 years ago)
- Last Synced: 2025-08-23T19:30:35.307Z (10 months ago)
- Topics: json, mysql, php7, php8, rest-api, shorturl, xp-framework
- Language: PHP
- Homepage:
- Size: 56.6 KB
- Stars: 1
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
ShortURL
========
[](https://github.com/thekid/shorturl/actions)
[](https://github.com/xp-framework/core)
[](https://github.com/xp-framework/core/blob/master/LICENCE.md)
[](http://php.net/)
[](http://php.net/)

URL Shortener service
Setup
-----
Create a database:
```sql
create database HUDDLE
use HUDDLE
create table url (id varchar(40) not null PRIMARY KEY, value varchar(1024))
grant all on HUDDLE.* to 'huddle'@'%' identified by '...'
```
Run composer:
```sh
$ composer install
# ...
```
Running
-------
Start the server:
```sh
$ export HUDDLE_PASS=...
$ xp -supervise web -c src/main/etc/prod de.thekid.shorturl.Api
```
Working with the service
------------------------
Create a URL:
```sh
$ curl -i localhost:8080 -d "url=https://github.com/"
HTTP/1.1 201
Date: Sun, 14 Aug 2016 10:25:39 GMT
Location: /d7b3438
```
Access the URL:
```sh
$ curl -i localhost:8080/d7b3438
HTTP/1.1 302
Date: Sun, 14 Aug 2016 10:26:17 GMT
Location: https://github.com/
```
Create a named URL:
```sh
$ curl -i localhost:8080 -d "url=http://thekid.de/&name=home"
HTTP/1.1 201
Date: Sun, 14 Aug 2016 10:25:39 GMT
Location: /home
```
Administering the service
-------------------------
List URLs:
```sh
$ curl -i admin:$HUDDLE_PASS@localhost:8080
HTTP/1.1 200
Date: Sun, 14 Aug 2016 10:39:42 GMT
Content-Type: application/json
[{"id":"d7b3438","value":"https://github.com/"},{"id":"home","value":"http://thekid.de/"}]
```
Delete URLs:
```sh
$ curl -i -X DELETE admin:$HUDDLE_PASS@localhost:8080/d7b3438
HTTP/1.1 204
Date: Sun, 14 Aug 2016 10:38:26 GMT
```