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
andnode-fetch
packages. -
Configure the
PORT
andapp.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:
-
Ensure both
express
andnode-fetch
packages are installed and imported. -
Make POST request using fetch to the REST API below from JSON Placeholder:
https://jsonplaceholder.typicode.com/todos
- Insert the object below into the body of the POST request:
let course = {
userId: 101,
title: "MEAN Stack course on Educative",
completed: true
}
- 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 1400+ tech skills courses.