/easyhttp

A minimal library for making http requests built wit vanilla javascript

Primary LanguageJavaScriptMIT LicenseMIT

easyhttp

A minimal library for making http requests built with vanilla javascript

HTTP Methods

get

post

put

delete

Usage

Include the easyhttp library into your source file before your custom javascript file.

EasyHTTP Example

<script src="easyhttp.js"></script>
<script src="app.js"></script>

Instantiate the library

const http = new EasyHTTP;

To make get request {api used in this example is Jsonplaceholder, a fake rest api}

-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));

To make a post request

-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));

To make a put request

-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));

To make a delete request

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));