Forismatic API help

Hello,

I’m working on the random quote machine project right now. I’m trying not to take the easy way out so I’m doing this with an api instead of hard coding random quotes to use. I’m running into some trouble though as the previous lessons on FCC about this aren’t so comprehensive. I’ve followed a youtube tutorial which assisted me in writing the following function which correctly generates and displays a quote/author on my page:

function getQuote () {
   var url = "http://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=?";
  $.getJSON(url, function(data) {
    $("#quote").html('"' + data.quoteText + '"');
    $("#author").html('-' + data.quoteAuthor);
  });
}

I had to copy his url exactly to get it to work. I don’t understand how this was created. The Forismatic documentation seems pretty unclear as well so I’m hoping someone can explain why this url is created the way it is.

Thank you in advance :slight_smile:

The URL is passing options along as a query string.

The structure of query strings is like this:

?key=value&key=value…etc

I used $ajax instead of getJSON, and constructed the options as an object instead:

$.ajax({
  jsonp: "jsonp",
  dataType: "jsonp",
  url: "http://api.forismatic.com/api/1.0/",
  contentType: "application/jsonp",
  data: {
    lang: "en",
    method: "getQuote",
    format: 'jsonp'
  },
  success: function(data) { .........

This uses the structure
Key: value,
Key: value
But communicates the same kind of detail to the API.

And, yeah, the forismatic docs are pretty bad.

Wait until you see the Wikipedia one :scream: