UNPKG

turtlefetch

Version:

Eaisily fetch from api with turtlefetch!

20 lines (16 loc) 637 B
const TurtleFetch = require('./turtlefetch'); // Initialize TurtleFetch with a base URL and default headers const apiClient = new TurtleFetch('https://api.example.com', { headers: { Authorization: 'Bearer YOUR_TOKEN', 'Custom-Header': 'MyHeaderValue', }, }); // Example GET request apiClient.get('/data') .then((data) => console.log('GET Response:', data)) .catch((error) => console.error('GET Error:', error)); // Example POST request apiClient.post('/data', { key: 'value' }) .then((response) => console.log('POST Response:', response)) .catch((error) => console.error('POST Error:', error));