This repository is part of the project briefly. Briefly project is a URL shortcoder.
This repository concern the REST service to expose with gin-tonic golang library
POST method: /shortcoder
POST json body:
{"url": "http://www.google.fr"}
GET a id of the URL in return HTTP code 200
GET method: /unshortcoder/:hash
hash: id of the URL
A redirect HTTP code 301 with the unshortcoded URL associated to the path parameter hash
Please install mage
$ mage
An artifact named 'briefly.public' is generated in './bin/' folder
The briefly gRPC server have to run to execute the backend work.
Please clone and follow documentation of briefly gRPC, to have a running gRPC server.
$ ./bin/briefly.public config new
will generate a default configuration file
###############################
# Briefly.public Settings
###############################
[Briefly_public]
###############################
# Briefly gRPC API settings
###############################
[Briefly_public.Briefly]
# URL and Port for the Briefly gRPC server
adress = "localhost:5556"
###############################
# REST API settings
###############################
[Briefly_public.REST]
# On which port REST HTTP service will listen
listenPort = ":8080"
###############################
# Logs Settings
###############################
[Log]
# Allow to display logs in Json format if true
jsonformatter = false
# Log level: trace, debug, info, warning, error, panic, and fatal
level = "warning"
store it as toml file in example in 'conf' folder onto './conf/briefly.public.conf.toml' file
$ ./bin/briefly.public startHttp --config ./conf/briefly.public.conf.toml
$ curl -X POST http://127.0.0.1:8080/shortcoder/ -H 'content-type: application/json' -d '{ "url": "https://www.google.com" }'
2073697506084
$ curl 127.0.0.1:8080/unshortcoder/2073697506084
<a href="https://www.google.com">Moved Permanently</a>.