@@ -33,6 +33,7 @@ To get Shorty up'n running follow these simple steps:
33
33
- clone the repository
34
34
- run composer install`
35
35
- change the ` PUT_TOKEN ` inside the .env file to something you prefer
36
+ - change the ` DELETE_TOKEN ` inside the .env file to something you prefer
36
37
- run ` php bin/console doctrine:database:create ` to create the database
37
38
- run ` php bin/console doctrine:migrations:migrate --no-interaction ` to setup the schema
38
39
- navigate to /public and run the local PHP Server with ` php -S 127.0.0.1:8000 `
@@ -59,13 +60,13 @@ you that Shorty is going out to have a cup of tea if there is some free time.
59
60
### Create a short link
60
61
If you want that Shorty creates a short link for you, you have to send
61
62
him a PUT request. The following example will show you how it works with
62
- curl from a mac .
63
+ curl in the terminal .
63
64
64
65
```
65
66
curl -X PUT -H 'Authorization: 5449f071773861dca4d3b459aa79fcf5' -d 'https://github.com/patrick-blom/shorty' http://127.0.0.1:8000
66
67
```
67
68
```
68
- -X PUT: tell curl to send a PUT request
69
+ -X PUT: Tell curl to send a PUT request
69
70
-H 'Authorization: 5449f071773861dca4d3b459aa79fcf5': The token you provide under .env PUT_TOKEN (5449f071773861dca4d3b459aa79fcf5)
70
71
-d 'https://github.com/patrick-blom/shorty': The Url you want to short (must be a syntactical valid url)
71
72
http://127.0.0.1:8000: Your running Shorty
@@ -86,6 +87,37 @@ Shorty will now take the identifier and search for it in his database.
86
87
If he finds a result he will pass a 301 HTTP Response including the
87
88
original url back to the browser.
88
89
90
+ ### Delete a short link
91
+ Sometimes it happens that you pass something to Shorty you want to delete
92
+ later. This can happen for several reasons. One reason could be that there is a typo
93
+ in your very long url and you don't want to mess up the database. Another one
94
+ could be, that you only want to share the short link for a limited amount of time.
95
+ Never mind, there can always be a reason for the deletion of a short link. So if
96
+ you want to delete a short link you have to send Shorty a DELETE request with the
97
+ created short code. If we take the example from above, it would look like this.
98
+
99
+ ```
100
+ curl -X DELETE -H 'Authorization: 5449f071773861dca4d3b459aa79fcf5' -d '950a0065' http://127.0.0.1:8000
101
+ ```
102
+ ```
103
+ -X DELETE: Tell curl to send a DELETE request
104
+ -H 'Authorization: 5449f071773861dca4d3b459aa79fcf5': The token you provide under .env DELETE_TOKEN (5449f071773861dca4d3b459aa79fcf5)
105
+ -d '950a0065': The short code which was created by Shorty during the PUT request
106
+ http://127.0.0.1:8000: Your running Shorty
107
+ ```
108
+
109
+ If everything works as expected, Shorty will return a 410 HTTP Gone Response.
110
+ Otherwise you will end up with an 400 HTTP Bad Request Response.
111
+
112
+ ### Security
113
+ Shorty's defense is really simple. The only thing between the world and the database
114
+ are your authorization tokens. So please keep the following recommendations in mind
115
+
116
+ - choose long and complex tokens
117
+ - never share your tokens
118
+ - never use the same token for PUT and DELETE
119
+ - always use HTTPS, if you can
120
+
89
121
## Testing
90
122
If you want to test Shorty you can this by simply run a regular
91
123
` composer install ` and ` composer test ` in the project root. This will
0 commit comments