From 7d69b3c71050cf3285f9f1f68d85d2b23b5a2115 Mon Sep 17 00:00:00 2001 From: Sebastian Preisner Date: Fri, 12 May 2017 22:46:50 +0000 Subject: [PATCH] Restful API Doku --- README.md | 55 ++++++++++++++++++++++++------------------------------- 1 file changed, 24 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 4fc5abe..770ba87 100644 --- a/README.md +++ b/README.md @@ -5,44 +5,37 @@ Shrt is a url shortner writen in Go and by (Polr)[https://polr.me/index.php]. ## Features -[x] No duplicated URL -[x] Simple UI -[x] DB simple json file -[x] Count URL views -[] Statistiks -[] Delete URL -[] Login +* [x] No duplicated URL +* [x] Simple UI +* [x] DB simple json file +* [x] Count URL views +* [] Statistiks +* [] Delete URL +* [] Login -## Problem -Problem liegt derzeit bei der Verwendung von shrt.Get mit der übergabe eines inteface. +## Restful API +Short an URL ``` -package main +GET: http://example.com/api/action/shorten?key=API_KEY_HERE&url=http://example.de/shortening/main?q=5x -... - -var redirect string -if ok := shrt.Get(token, &redirect); ok { - // do something with the redirect. -} +Response: +{ "action": "shorten", + "result": "https://example.com/5kq" } ``` -Entgegen genommen wird es bei `lib/shrt.go`: +Lookup for existing URL ``` -// Get returns the URL for the given token -func (s *Storage) Get(token string, value interface{}) bool { - if hash, ok := s.Token[token]; ok { - fmt.Printf("Url gefunden %s mit Hash: %v \n", s.Url[hash].URL, hash) - value = s.Url[hash].URL - fmt.Printf("Value: %V \n", value) - return true - } - return false +GET: http://example.com/api/action/lookup?key=API_KEY_HERE&url_ending=5kq + +Response: +{ "action":"lookup", + "result": { + "long_url": "http://example.de/shortening/main?q=5x", + "created_at": "2017-05-12 22:48:40.997520107 +0200 CEST", + "clicks":"0" + } } -``` - -Ich dachte eigentlich ich könne redirect damit manipulieren wenn ich es als pointer auf redirect übergebe aber das scheint nicht so zu sein.... - - +``` \ No newline at end of file