Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/bolajiayodeji/simple-ajax-library

A simple AJAX Library for making HTTP Requests
https://github.com/bolajiayodeji/simple-ajax-library

ajax ajax-request http library

Last synced: 3 months ago
JSON representation

A simple AJAX Library for making HTTP Requests

Awesome Lists containing this project

README

        

# Getting Started

Download and include the JavaScript file | [full version](https://github.com/BolajiAyodeji/simple-ajax-library/blob/master/dist/simpleAjax.js) | [minified](https://github.com/BolajiAyodeji/simple-ajax-library/blob/master/dist/simpleAjax.min.js) | [ES6 version](https://github.com/BolajiAyodeji/simple-ajax-library/blob/master/src/simpleAjax.js) |

```html

```
```html

```
Create a new simpleAjax
```js
const http = new simpleAJAX;
```

# Examples

* GET Request

```js
users = http.get('https://jsonplaceholder.typicode.com/users',
(err, users) => {
if(err) {
console.log(err)
} else {
console.log(users);
}
});
```

* POST Request

```js
const data = {
"name": "Bolaji Ayodeji",
"username": "bolajiayodeji",
"email": "[email protected]",
"address": {
"street": "Hello world",
"suite": "Hello",
"city": "Lokoja, Kogi",
"zipcode": "xxx-xxx-xxx",
"geo": {
"lat": "29.4572",
"lng": "-164.2990"
}
},
"phone": "+234 8109445504",
"website": "https://bolajiayodeji.com",
"company": {
"name": "PhilanthroLab",
"catchPhrase": "Multi-tiered zero tolerance productivity",
"bs": "transition cutting-edge web services"
}
};

http.post('https://jsonplaceholder.typicode.com/users',
data, (err, user) => {
if(err) {
console.log(err)
} else {
console.log(user);
}
});
```

* PUT Request

```js
const data = {
"name": "Bolaji Ayodeji",
"username": "bolajiayodeji",
"email": "[email protected]",
"address": {
"street": "Hello world",
"suite": "Hello",
"city": "Lokoja, Kogi",
"zipcode": "xxx-xxx-xxx",
"geo": {
"lat": "29.4572",
"lng": "-164.2990"
}
},
"phone": "+234 8109445504",
"website": "https://bolajiayodeji.com",
"company": {
"name": "PhilanthroLab",
"catchPhrase": "Multi-tiered zero tolerance productivity",
"bs": "transition cutting-edge web services"
}
};

http.put('https://jsonplaceholder.typicode.com/users/1',
data, (err, user) => {
if(err) {
console.log(err)
} else {
console.log(user);
}
});
```

* DELETE Request

```js
users = http.delete('https://jsonplaceholder.typicode.com/users/1',
(err, response) => {
if(err) {
console.log(err)
} else {
console.log(response);
}
});
```

# Demo
Demo [here](https://bolajiayodeji.github.io/simple-ajax-library/demo/)

# Contribution Guide

```bash
git clone https://github.com/BolajiAyodeji/simple-ajax-library.git
```
```bash
cd simple-ajax-library
```
```bash
npm install
```
```bash
npm run build
```