The baconipsum.com API is a REST interface that returns JSON. Pass in the following parameters using an HTTP GET and we’ll return a JSON string array of paragraphs.
It can also be accessed via https.
Parameters:
- type: all-meat for meat only or meat-and-filler for meat mixed with miscellaneous ‘lorem ipsum’ filler.
- paras: optional number of paragraphs, defaults to 5.
- sentences: number of sentences (this overrides paragraphs)
- start-with-lorem: optional pass 1 to start the first paragraph with ‘Bacon ipsum dolor sit amet’.
Examples:
- http://baconipsum.com/api/?type=meat-and-filler
- https://baconipsum.com/api/?type=all-meat¶s=2&start-with-lorem=1
- https://baconipsum.com/api/?type=all-meat&sentences=1&start-with-lorem=1
Some sample jquery code!
$(document).ready(function()
{
$("#baconButton").click(function()
{
$.getJSON('https://baconipsum.com/api/?callback=?',
{ 'type':'meat-and-filler', 'start-with-lorem':'1', 'paras':'3' },
function(baconGoodness)
{
if (baconGoodness && baconGoodness.length > 0)
{
$("#baconIpsumOutput").html('');
for (var i = 0; i < baconGoodness.length; i++)
$("#baconIpsumOutput").append('<p>' + baconGoodness[i] + '</p>');
$("#baconIpsumOutput").show();
}
});
});
});
Run the sample!
Dudes. This is awesome. That is all!
Can’t stop laughing…
Very nice!
To be honest: It’s TOO funny. I wasn’t able to produce a single line of serious code the last 2 hours.
+1 for Turducken!
beautiful and tasty!
Great!
Can you please make it so this can work with CORS? Currently the baconipsum API can’t be used by many Javascript frameworks, the browser denies access (because you don’t explicitly specify otherwise).
To fix this, you need to make your server push out the following header with your JSON response:
Access-Control-Allow-Origin: *
More details here: http://www.html5rocks.com/en/tutorials/cors/#toc-adding-cors-support-to-the-server
Thanks in advance!
Hey — thanks for the awesome super quick fix-up!
Pingback: Web developer tools | The Misadventures of a Pagan Geek
Excellent!
Thanks.