This project provides an introduction to making HTTP requests in JavaScript. It is intended for use in Thinkful's Web Development curriculum, providing students with hands-on experience using JavaScript to interact with APIs.
- Clone the repository:
git clone https://github.com/Thinkful-Ed/example-making-requests-requests-in-javascript.git
- Navigate into the project directory:
cd example-making-requests-requests-in-javascript
- Install dependencies:
npm install
- Start the development server:
npm start
This project demonstrates how to use JavaScript to make HTTP requests to external APIs. It covers:
- Sending
GET
,POST
,PUT
, andDELETE
requests using JavaScript. - Handling asynchronous code using promises and async/await.
- Working with APIs by sending data and handling responses.
-
Making GET Requests:
- You will learn how to fetch data from an external API using the
fetch
function and handle the returned promise. - Example:
fetch('https://api.example.com/data') .then(response => response.json()) .then(data => console.log(data));
- You will learn how to fetch data from an external API using the
-
Sending POST Requests:
- This project also demonstrates how to send data to an API using a POST request.
- Example:
fetch('https://api.example.com/data', { method: 'POST', body: JSON.stringify({ key1: 'value1', key2: 'value2' }), headers: { 'Content-Type': 'application/json' } });
-
Error Handling:
- You will also learn how to handle errors in HTTP requests using
.catch()
for promises andtry...catch
with async/await.
- You will also learn how to handle errors in HTTP requests using