A minimal library for making http requests built with vanilla javascript
get
post
put
delete
Include the easyhttp library into your source file before your custom javascript file.<script src="easyhttp.js"></script>
<script src="app.js"></script>
-Basic barebone http.get('API ENDPOINT'){}
//Get posts
http.get('https://jsonplaceholder.typicode.com/posts')
.then(data => console.log(data))
.catch(err => console.log(err));
//Get single post
http.get('https://jsonplaceholder.typicode.com/posts/1')
.then(data => console.log(data))
.catch(err => console.log(err));
-Basic barebone http.post('API ENDPOINT', DATA){}
//Create Data
const data = {
title: 'Custom Post',
body: 'This is a custom post'
};
//Create Post
http.post('https://jsonplaceholder.typicode.com/posts', data)
.then(data => console.log(data))
.catch(err => console.log(err));
-Basic barebone http.put('API ENDPOINT', DATA, CALLBACK FUNCTION){}
//Update post
http.put('https://jsonplaceholder.typicode.com/posts/5', data)
.then(data => console.log(data))
.catch(err => console.log(err));
Basic barebone http.delete('API ENDPOINT'){}
//Delete post
http.delete('https://jsonplaceholder.typicode.com/users/2')
.then(data => console.log(data))
.catch(err => console.log(err));