Challenge: Making POST and GET Requests to a Public REST API

Learn to make a POST and GET request to a public REST API.

Challenge description for making a GET request

This part of the exercise is implemented by taking the following steps:

  • Install and import both the express and node-fetch packages.

  • Configure the PORT and app.listen() in Express.

  • Make a GET request using the fetch npm package to the REST API below from JSONPlaceholder:

https://jsonplaceholder.typicode.com/posts
  • The GET request should display only the first post from the REST API inside of the console, and the result should look like what we have below:
{
  userId: 1,
  id: 1,
  title: 'sunt aut facere repellat provident occaecati excepturi optio reprehenderit',
  body: 'quia et suscipit\n' +
    'suscipit recusandae consequuntur expedita et cum\n' +
    'reprehenderit molestiae ut ut quas totam\n' +
    'nostrum rerum est autem sunt rem eveniet architecto'
}

Challenge description for making a POST request

This part of the exercise is implemented by taking the following steps:

  1. Ensure both express and node-fetch packages are installed and imported.

  2. Make POST request using fetch to the REST API below from JSON Placeholder:

https://jsonplaceholder.typicode.com/todos
  1. Insert the object below into the body of the POST request:
let course = {
  userId: 101,
  title: "MEAN Stack course on Educative",
  completed: true
}
  1. Log the resulting response from the POST request into the console. Our result should look like what we have inside of the console below:
{
  userId: 101,
  title: 'MEAN Stack course on Educative',
  completed: true,
  id: 201
}

Get hands-on with 1200+ tech skills courses.