To try this example, you need GNU make and git in your PATH.
If you don’t have HTTPie installed, use the appropriate cURL commands instead.
To build the example, run the following command:
makeTo start the release in the foreground:
./_rel/rest-pastebin-example/bin/rest-pastebin-example consoleNote: The previous command also starts an Erlang console.
To start the app and an LFE shell:
lfe -pa ebin -pa deps/*/ebin -s rest-pastebin # make devPoint your browser at http://localhost:8080.
To upload something to the pastebin application, you can use http:
http -f :8080 paste=(<command>) Content-Type:application/x-www-form-urlencodedOr, to upload the file my-file:
http -f :8080 paste=@my-file Content-Type:application/x-www-form-urlencodedThe URL of your data will be in the location header. Alternately, you can visit http://localhost:8080 with your favorite web browser and submit your paste via the form.
Code that has been pasted can be highlighted with ?lang=<language> option if
you have highlight installed (although pygments or any other should work just
fine).
This will show the contents of the HTML file:
http -vf --follow :8080 paste=@priv/index.html \
Content-Type:application/x-www-form-urlencoded # drop charset=utf-8If your terminal supports color sequences and highlight is installed, the
following command will show the same contents but with HTML syntax highlighting.
http <url from location header> lang==htmlhttp -vf --follow :8080 paste=(echo 'Testing 123') \
Content-Type:application/x-www-form-urlencoded # drop charset=utf-8GET /oZCkVBbs HTTP/1.1
Accept-Encoding: gzip, deflate
Host: localhost:8080
Accept: */*
User-Agent: HTTPie/0.9.3
Connection: keep-alive
Content-Type: application/x-www-form-urlencodedHTTP/1.1 200 OK
server: Cowboy
date: Tue, 05 Jan 2016 22:09:19 GMT
content-length: 12
content-type: text/plain
vary: acceptTesting 123
http -vf --follow :8080 paste=@priv/index.html \
Content-Type:application/x-www-form-urlencoded # drop charset=utf-8GET /H3s2MhU2 HTTP/1.1
Accept-Encoding: gzip, deflate
Host: localhost:8080
Accept: */*
User-Agent: HTTPie/0.9.3
Connection: keep-alive
Content-Type: application/x-www-form-urlencodedHTTP/1.1 200 OK
server: Cowboy
date: Tue, 05 Jan 2016 22:02:30 GMT
content-length: 543
content-type: text/plain
vary: accept<!DOCTYPE html>
<html>
<head>
<title>Simple Pastebin</title>
</head>
<body>
<h1>Simple Pastebin</h1>
<p>
You can paste your text into the text field to submit, or you can
capture the output of a command with:
</p>
<code>
<i>command</i> | curl -i --data-urlencode paste@- localhost:8080
</code>
<form action="/" method="post">
<textarea cols="80" rows="15" name="paste"></textarea>
<div>
<button type="submit">Upload your code</button>
</div>
</form>
</body>
</html>