I am absolutely Confused on the API Forismatics

so I am doing my random quote machine (which is not that good) and I started by setting up an array but then I came across the API forismatic site and decided that that would be a better option but have no clue where to start.Any help is appreciated thx .

this is my project (comments welcome):

Don’t get frustrated. APIs are very confusing. They are confusing enough, and every one is different and the documentation is often poor and they can change without you even knowing it.

var corsString = "https://cors-anywhere.herokuapp.com/";
var apiString = "api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=json&json=?";

$.ajax({
    url: corsString + apiString,
  })
  .done(function(data) {
    console.log(data);
    $("body").html(data.quoteText + " - " + data.quoteAuthor);
  })
  .fail(function(err) {
    console.log('Error: ' + err.status);
  });

This would be a simple call to Forismatic. The corsString is needed … err … because of CORS. I suggest you read up on that or check out a youtube video.

This will require you to load JQuery in codepen -> Settings/JavaScript/Quick-Add.

There are other ways to make an API call, but I find $.ajax to be the easiest to grasp at first.

This is a more verbose way, but avoids the need for the CORS workaround.

 $.ajax({
      url: "https://api.forismatic.com/api/1.0/",
      jsonp: "jsonp",
      dataType: "jsonp",
      data: {
        method: "getQuote",
        lang: "en",
        format: "jsonp"
      }
    })
    .done(function(data) {
      console.log(data);
      $("body").html(data.quoteText + " - " + data.quoteAuthor);
    })
    .fail(function(err) {
      console.log('Error: ' + err.status);
    });
1 Like

ok I just spent the last hour looking for anything (free) that helps an have not found not a single course nor from Udacity Udemy courser edx or even class-central so could you please if you don’t mind explain to me how to implement the api in my random quote machine because I have found nothing on the topic.

I found it was much less of a headache to code your own random quote machine, super easy and good practice to put javascript into a web page. There are plenty more opportunities to learn and work with better documented APIs in the later challenges.

thank you very much you saved me so much time and the project turned out pretty well.

if you want to see it here it is