No description
- JavaScript 100%
| node_modules | ||
| Deliverable.js | ||
| package-lock.json | ||
| package.json | ||
| README.md | ||
| Server.js | ||
API Practice
This project is for me to practice how to interact with API's with JavaScript & Postman. I intend to answer the following questions with this lesson:
- How do I make a GET request to retrieve data?
- How do I make a POST request to send data?
- How do I handle errors when interacting with an API?
Table of Contents
Setup
Prerequisites
- Node.js installed on your machine.
- Postman for API testing.
Installation
-
Clone the repository:
git clone https://github.com/yourusername/API-Practice.git -
Navigate to the project directory:
cd API-Practice -
Install any necessary dependencies (if any):
npm install
Usage
Making GET Requests
To make a GET request, you can use JavaScript with the fetch API or Postman.
Using JavaScript:
fetch('https://api.example.com/data')
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
Using Postman:
- Open Postman.
- Select the GET method.
- Enter the URL:
https://api.example.com/data. - Click "Send".
Making POST Requests
To make a POST request, you can use JavaScript with the fetch API or Postman.
Using JavaScript:
const data = {
name: 'John Doe',
email: 'john.doe@example.com'
};
fetch('https://api.example.com/data', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
Using Postman:
- Open Postman.
- Select the POST method.
- Enter the URL:
https://api.example.com/data. - Go to the "Body" tab and select "raw".
- Choose "JSON" from the dropdown.
- Enter your JSON data:
{ "name": "John Doe", "email": "john.doe@example.com" } - Click "Send".
Contributing
Contributions are welcome! Please read our CONTRIBUTING.md file for details on how to contribute.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Feel free to modify this template to fit your specific needs and questions.