URL shortener: Difference between revisions
m
syntax highlighting fixup automation
(→{{header|Wren}}: Added libheader.) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 43:
{{libheader| kemal}}
<
CHARS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".chars
Line 66:
end
Kemal.run</
=={{header|Delphi}}==
Line 78:
{{libheader| Inifiles}}
Highly inspired in [[#Go]]
<syntaxhighlight lang="delphi">
program URLShortenerServer;
Line 244:
Manager.Free;
end.</
{{out}}
<pre>
Line 251:
</pre>
=={{header|Go}}==
<
package main
Line 319:
db := make(database)
log.Fatal(http.ListenAndServe(host, db))
}</
{{out}}
Line 355:
=={{header|JavaScript}}==
{{works with|Node.js}}
<
var mapping = new Map();
Line 402:
res.writeHead(404);
res.end();
}).listen(8080);</
{{out}}
<pre>$ curl -X POST http://localhost:8080/ -H "Content-Type: application/json" --data "{\"long\":\"https://www.example.com\"}"
Line 411:
=={{header|Julia}}==
Assumes an SQLite database containing a table called LONGNAMESHORTNAME (consisting of two string columns) already exists.
<
function processpost(req::HTTP.Request, urilen=8)
Line 456:
const localport = 3000
run_web_server(serveraddress, localport)
</syntaxhighlight>
=={{header|Objeck}}==
<
use Data.JSON;
use Web.HTTP;
Line 520:
return Response->New(200, response);
}
}</
=={{header|Phix}}==
<!--<
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\URL_shortener.exw
Line 628:
<span style="color: #000000;">sock</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">closesocket</span><span style="color: #0000FF;">(</span><span style="color: #000000;">sock</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">WSACleanup</span><span style="color: #0000FF;">()</span>
<!--</
{{out}}
Sample session output:
Line 674:
=={{header|PicoLisp}}==
<
(allowed NIL "!short" u)
(pool "urls.db" (6))
Line 685:
(commit 'upd)
(respond (pack "http://127.0.0.1:8080/?" K "\n")) ) ) )
(server 8080 "!short")</
{{out}}
<pre>
Line 719:
===Flask===
{{libheader|Flask}}
<
"""A URL shortener using Flask. Requires Python >=3.5."""
Line 904:
app.env = "development"
app.run(debug=True)
</syntaxhighlight>
=={{header|Raku}}==
Line 919:
There is '''NO''' security or authentication on this minimal app. Not recommended to run this as-is on a public facing server. It would not be too difficult to ''add'' appropriate security, but it isn't a requirement of this task. Very minimal error checking and recovery.
<syntaxhighlight lang="raku"
use JSON::Fast;
Line 975:
react whenever signal(SIGINT) { $shorten.stop; exit; }
</syntaxhighlight>
=={{header|Wren}}==
Line 982:
{{libheader|Wren-json}}
An embedded program with a Go host so we can use its net/http module.
<
import "./json" for JSON
Line 1,041:
foreign static redirect(url, code)
}</
We now embed this script in the following Go program and build it.
<
package main
Line 1,154:
log.Fatal(http.ListenAndServe(host, nil))
vm.Free()
}</
{{out}}
Sample output (abbreviated) including building and starting the server from Ubuntu 20.04 terminal and entering a valid and then an invalid shortened URL:
|