JSON API

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:

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!

13 Responses to JSON API

  1. Vanessa says:

    Dudes. This is awesome. That is all!

  2. violacase says:

    Can’t stop laughing…
    Very nice!

  3. violacase says:

    To be honest: It’s TOO funny. I wasn’t able to produce a single line of serious code the last 2 hours.

  4. sameer says:

    beautiful and tasty!

  5. Jim Smart says:

    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!

  6. Jim Smart says:

    Hey — thanks for the awesome super quick fix-up! :)

  7. Pingback: Web developer tools | The Misadventures of a Pagan Geek

  8. Surekha says:

    Excellent!
    Thanks.

  9. Daniel Furze says:

    Wicked cool, thanks! :D

  10. Pall Thayer says:

    This is awesome. However, the api returns text with two spaces after a period. This is wrong. There should only be a single space after a period. http://www.slate.com/articles/technology/technology/2011/01/space_invaders.html

  11. @GunGeekATX says:

    You can always branch and do a pull request if you’d like anything changed: https://github.com/petenelson/bacon-ipsum

  12. Marnix says:

    *OINK*

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>