This repository contains a script to study from your browser's devtools. You'll see how to make calls to a RESTful API, and when to use async/await.
- Stepping through API calls in the debugger
fetch
ing the main RESTful verbs- GET, POST, PUT, PATCH, DELETE
- Understanding when to use await
To install and run the application:
npm install
npm run start
- open
localhost:3000
in the browser
That's it! You're now ready to study public/example-fetches.js
.
When you start this project, a server will open up on localhost:3000
. Navigate to this URL in your browser, open your devtools and refresh. You will find yourself at the top of a script full of API calls. Step through these calls one at a time paying extra attention to:
- When is await used, and when are normal promises used?
- When do responses come back? How does this change because of await?
- What happens in your Node.js terminal each time you send a request?
- What happens in
db.json
each time you send a request?
This project's backend is generated automatically using the json-server module, the same module that is used to run the jsonplaceholder API. Studying the jsonplaceholder guide will be helpful.
Heads Up! Running the example script without pausing in the debugger will sometimes cause errors (and sometimes won't, it's a bit random). This is because running
json-server
locally does not create a high-performance server. It needs to restart every once in a while afterdb.json
has been changed. As long as you step through the example fetches in your debugger you will have no troubles.