Giter Site home page Giter Site logo

jsdom-toy-tale-online-web-ft-071519's Introduction

Toy Tale

You've got a friend in need! Your friend Andy recently misplaced all their toys! Help Andy recover their toys and get the toys back in the toy collection.

Create Your Server

All of the toy data is stored in the db.json file. You'll want to access this data using a JSON server. In order to do this, run the following two commands:

  • npm install -g json-server
  • json-server --watch db.json

This will create a server storing all of our lost toy data with restful routes at http://localhost:3000/toys. You can also check out http://localhost:3000/toys/:id

Fetch Andy's Toys

On the index.html page, there is a div with the id "toy-collection."

When the page loads, make a 'GET' request to fetch all the toy objects. With the response data, make a <div class="card"> for each toy and add it to the toy-collection div.

Add Toy Info to the Card

Each card should have the following child elements:

  • h2 tag with the toy's name
  • img tag with the src of the toy's image attribute and the class name "toy-avatar"
  • p tag with how many likes that toy has
  • button tag with a class "like-btn"

After all of that, the toy card should resemble:

  <div class="card">
    <h2>Woody</h2>
    <img src=toy_image_url class="toy-avatar" />
    <p>4 Likes </p>
    <button class="like-btn">Like <3</button>
  </div>

Add a New Toy

When a user submits the toy form, two things should happen:

  • a POST request should be sent to http://localhost:3000/toys and the new toy added to Andy's Toy Collection.
  • If the post is successful, the toy should be added to the DOM without reloading the page.

In order to send a POST request via Fetch, give the Fetch a second argument of an object. This object should specify the method as POST and also provide the appropriate headers and the JSON-ified data for the request. The headers and body should look something like this:

headers: 
{
  "Content-Type": "application/json",
  Accept: "application/json"
}

body: JSON.stringify({
  "name": "Jessie",
  "image": "https://vignette.wikia.nocookie.net/p__/images/8/88/Jessie_Toy_Story_3.png/revision/latest?cb=20161023024601&path-prefix=protagonist",
  "likes": 0
})

For examples, refer to the documentation.

Increase Toy's Likes

When a user clicks on a toy's like button, two things should happen:

  • A patch request (i.e., method: "PATCH") should be sent to the server at http://localhost:3000/toys/:id, updating the number of likes that the specific toy has
  • If the patch is successful, the toy's like count should be updated in the DOM without reloading the page

The headers and body should look something like this:

headers: 
{
  "Content-Type": "application/json",
  Accept: "application/json"
}

body: JSON.stringify({
  "likes": <new number>
})

If your request isn't working, make sure your headers and keys match the documentation.

jsdom-toy-tale-online-web-ft-071519's People

Contributors

aalexander3 avatar lizbur10 avatar ronricardo avatar amelieoller avatar thuyanduong-flatiron avatar dwire avatar ihollander avatar oldgcdm avatar hyeokjungkim avatar jerryjcchang avatar drakeltheryuujin avatar paulnicholsen27 avatar rrcobb avatar jonashaefele avatar maxwellbenton avatar vibraniumforge avatar

Watchers

James Cloos avatar  avatar  avatar Victoria Thevenot avatar Bernard Mordan avatar Otha avatar raza jafri avatar  avatar Joe Cardarelli avatar The Learn Team avatar Sophie DeBenedetto avatar  avatar  avatar Matt avatar Antoin avatar  avatar Alex Griffith avatar  avatar Amanda D'Avria avatar  avatar Ahmed avatar Nicole Kroese  avatar Kaeland Chatman avatar Lisa Jiang avatar Vicki Aubin avatar  avatar  avatar  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.