CajaxJS is an lightweight JS Http client for everyone!
npm install cajaxjs
<script src="https://js.gjni.eu/cajax.js"></script>
<!-- OR -->
<script src="https://js.gjni.eu/cajax/1.1.1.js"></script>
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.post("/myapi", { information:"easy to use" })
.then((data)=>{
console.log(data.responseText);
}).catch((data.responseText)=>{
console.log("Something exploded!: "+data);
}).send();
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);
});
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);
});
Cajax.js works with every newer browser (Except Internet Explorer)
Babel You can use Babel to get support for older browser
Cajax.post("/myapi.php", {hello:"world"})
.then((data)=>{
console.log(data.responseText);
}).catch((data)=>{
console.log("error"+data.responseText);
}).send();
Cajax.get("/myapi.php", {hello:"world"})
.then((data)=>{
console.log(data.responseText);
}).catch((data)=>{
console.log("error"+data.responseText);
}).send();
Cajax.get("/myapi.php")
.then((data)=>{
console.log(data.responseText);
}).catch((data)=>{
console.log("error"+data.responseText);
}).send();
Cajax.post("/myapi.php", {}, {header: {myheader: "HEAD"}})
.then((data)=>{
console.log(data.responseText);
}).catch((data)=>{
console.log("error"+data.responseText);
}).send();
Cajax.post("/myapi.php", {}, {withCredentials: true} })
.then((data)=>{
console.log(data.responseText);
}).catch((data)=>{
console.log("error"+data.responseText);
}).send();
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();
var $ = Cajax;
$.get("/myapi")
.then((data)=>{
console.log(data.responseText);
}).send();
var req = Cajax.post("example_server.php", {hello: "world"});
req.then((data)=>{
console.log(data.responseText);
});
req.send();
Author: interaapps
Demo: https://developers.interaapps.de/cajax
Source Code: https://github.com/interaapps/cajax
#deno #nodejs #node #javascript