Giter Site home page Giter Site logo

071023-ph1-04-async-js-and-fetch's Introduction

Asynchronous JS and Fetch GET Requests

Learning Goals

  • Nested data structures
  • Looping through data
  • Request-response cycle
  • HTTP Verbs
  • GET requests with external API
  • Handling promises from .fetch()
  • .catch() and the try / catch syntax

Dad Jokes API Endpoints

In order to use the Dad Jokes API we'll need the URL and a pair of special headers:

URL:

https://icanhazdadjoke.com/

Headers:

headers: {
  Accept: 'application/json'
}

For the json-server:

URL:

http://localhost:3000/jokes

Headers:

none

Practice

  1. Make an initial fetch request to the Dad Jokes API and add a new paragraph tag to the dad-jokes-container with the new joke.
  • HINT: Be sure to look at the data you get back so you know how to get the joke inside the response...
  1. When a user clicks the new-joke-button, make a fetch request to the Dad Jokes API and add a new paragraph tag to the dad-jokes-container with the new joke (just like above!)

  2. Start up json-server with json-sever --watch db.json. If you aren't able then attempt to install the json-server (installation depends on your OS). You can now fetch jokes from http://localhost:3000/jokes. Fetch the array of jokes, iterate through the array, and create a new paragraph tag for each joke just like above.

  • HINT: Once again make sure you look at the data you get back, it WILL be different from the dad jokes API

071023-ph1-04-async-js-and-fetch's People

Contributors

brewchetta avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.