Skip to content

A minimal library for making http requests built wit vanilla javascript

License

Notifications You must be signed in to change notification settings

akinlekan28/easyhttp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A minimal library for making http requests built wit vanilla javascript

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published