CajaxJS is an lightweight JS Http client for everyone!

CAJAX (ClassedAjax) Prajax (PromiseAjax) 1.0.6

CajaxJS is an lightweight JS Http client for everyone!

NPM
npm install cajaxjs

CDN

<script src="https://js.gjni.eu/cajax.js"></script>
<!-- OR -->
<script src="https://js.gjni.eu/cajax/1.1.1.js"></script>

CDN (module)

test.js

import Cajax from 'https://js.gjni.eu/cajax/src/Cajax.js'
// or import { Cajax } from 'https://js.gjni.eu/cajax/index.js'

Cajax.get("/").send()
// note that you have to use the script tag with type="module"
Cajax
Cajax.post("/myapi", { information:"easy to use" })
.then((data)=>{
    console.log(data.responseText);
}).catch((data.responseText)=>{
    console.log("Something exploded!: "+data);
}).send();
Prajax

Now you can use await

Prajax.post("/myapi", { information:"easy to use" })
.then((data)=>{
    console.log(data.responseText);
}).catch((data.responseText)=>{
    console.log("Something exploded!: "+data);
});

PrajaxClient

let client = new PrajaxClient({
   baseUrl: "https://interaapps.de",
   options: {
       header: {"x-key": "asd"}
   }
});

// USING application/json for post requests.
client.options.json = true;

client.get("/").then(res=>{
    console.log(res.responseText);
});

Features

  • Many request methods
  • Fully customizable

Request methods

  • GET
  • POST
  • PUT
  • DELETE
  • OPTIONS
  • TRACE
Browser support

Cajax.js works with every newer browser (Except Internet Explorer)

Babel You can use Babel to get support for older browser

Simple POST request
Cajax.post("/myapi.php", {hello:"world"})
.then((data)=>{
    console.log(data.responseText);
}).catch((data)=>{
    console.log("error"+data.responseText);
}).send();
Simple GET request (with get parameters)
Cajax.get("/myapi.php", {hello:"world"})
.then((data)=>{
    console.log(data.responseText);
}).catch((data)=>{
    console.log("error"+data.responseText);
}).send();
Simple GET request (without get parameters)
Cajax.get("/myapi.php")
.then((data)=>{
    console.log(data.responseText);
}).catch((data)=>{
    console.log("error"+data.responseText);
}).send();
Header
Cajax.post("/myapi.php", {}, {header: {myheader: "HEAD"}})
.then((data)=>{
    console.log(data.responseText);
}).catch((data)=>{
    console.log("error"+data.responseText);
}).send();
XHR Options (Example: withCredentials)
Cajax.post("/myapi.php", {}, {withCredentials: true} })
.then((data)=>{
    console.log(data.responseText);
}).catch((data)=>{
    console.log("error"+data.responseText);
}).send();
Customizable
Cajax.get("/myapi.php", {hello:"world"})
.then((data)=>{
    console.log(data.responseText);
}).catch((data)=>{
    console.log("error"+data.responseText);
}).custom((xhr)=> {
	// You can use all XMLHttpRequest methods
	xhr.send("custom things");
}).send();
Own classname
var $ = Cajax;

$.get("/myapi")
.then((data)=>{
    console.log(data.responseText);
}).send();
Split
var req = Cajax.post("example_server.php", {hello: "world"});
req.then((data)=>{
    console.log(data.responseText);
});
req.send();

Download Details:

Author: interaapps

Demo: https://developers.interaapps.de/cajax

Source Code: https://github.com/interaapps/cajax

#deno #nodejs #node #javascript

CajaxJS is an lightweight JS Http client for everyone!
2.30 GEEK