Coder Social home page Coder Social logo

practice-for-week-08-fetch's Introduction

Practice: fetch

In this exercise, you will practice extracting the response components from GET requests made with fetch on the browser.

Set up

The server you will be making requests to is the same server from the HTTP Basics practice seen a few days prior.

cd into the server folder and run npm install.

Start the server by running npm start.

This will start the server at http://localhost:5000.

The documentation of this server is given in the solution of the HTTP Basics long practice assigned a few days prior.

Clone the practice from the starter.

Make fetch requests in the browser for each of the tasks in the fetch-requests.js file. Paste your code for the fetch requests in the file once you finish each task.

Extract the response components and print them

Make a GET request to the /products route using Postman. Take note of the necessary request components and the components of the response returned from the server.

Use the "Console" tab in the browser to make the equivalent fetch request.

Print the status code, the Content-Type header, and the body of the response as text in the console.

To extract these response components, use the following documented properties and methods on the Response object that the fetch function resolves to: MDN Documentation on the fetch Response object.

Here are some useful properties and methods on the Response object:

  • .status - status code of the response
  • .ok - returns true if the response was successful and false otherwise
  • .headers.get(headerName) - returns the value of the header with the given headerName
  • .text() - returns a Promise that resolves to the body of the response

Additional practice

Make GET requests to other routes in this server to practice formulating fetch requests. The documentation of this server is given in the solution of the HTTP Basics project assigned a few days prior.

practice-for-week-08-fetch's People

Contributors

aa-assessment-project-manager[bot] 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.