Skip to content

202309-EKTA-JO-FSW/intro-to-fetch-api-Sanad-Alshobaki

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Open in Visual Studio Code

Activity: Fetching and Modifying JSONPlaceholder User Data

In this activity, you will learn how to fetch user data from the JSONPlaceholder API, store it in a variable, and create modified objects for each user with specific fields using JavaScript.

Steps

Step 1: Write a Function to fetch data from the API Endpoint Provided.

  1. Write a JavaScript function (e.g., fetchUserData) in the provided index.js file that performs the following tasks:
  2. Fetch the data from https://jsonplaceholder.typicode.com/users using async/await.

Step 2: Store Data

  1. Inside the fetchUserData function, store the fetched user data in a variable (e.g., usersData).

Step 3: Modify Data

  1. Still within the fetchUserData function, create modified user objects (maybe by using an array iterator method like .map) for each user with specific fields as follows:

    • Name
    • Username
    • Email
    • Address (Street name only)
    • Phone
    • Website
    • Company (Company name only)

    and put these new objects in an array.

  2. Log the modified list.

Step 4: Filter the Data

  1. Filter the users data that you modified to display users only which have .biz domain in their email.
  2. Log the filtered list.

Step 5: Sort the Data

  1. Sort the users alphabetically by name.
  2. Log the sorted list.

Step 6: Catch the Errors

  1. Catch the errors and print out the error messages that might occur.

How to Run Your Program

You can open up a terminal in your working directory and run the command node index.js to run the program.

Alternatively, you can also use the nodemon package to make your program run in real time whenever you save your file. This might need some googling, but it is not very hard to do.

About

intro-to-fetch-api-Sanad-Alshobaki created by GitHub Classroom

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published