Skip to content

Commit

Permalink
Implemented axios post method for simple url
Browse files Browse the repository at this point in the history
  • Loading branch information
redoC-A2k committed May 25, 2024
1 parent 35a2faf commit 55786c1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
7 changes: 3 additions & 4 deletions JS/wasm/crates/arakoo-core/src/apis/http/shims/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,15 @@ class Request {
// }

constructor(url, input) {
console.log("In constructor of request , url = ",url, " input = ",input);
if (typeof url === "string") {
this.url = url
} else {
throw new Error("url in Request constructor is not a string")
}
this.headers = input.headers;
this.method = input.method;
let bodyArray = new Uint8Array(input.body);
let bodyString = decoder.decode(bodyArray);
if (bodyString != undefined && bodyString.length > 0)
this.body = JSON.parse(bodyString);
this.body = input.body;
this.params = input.params || {};
this.geo = input.geo || {};
}
Expand Down Expand Up @@ -368,6 +366,7 @@ function fetch(uri, options) {
options.method = uri.method;
options.params = uri.params;
options.geo = uri.geo;
options.body = uri.body;
uri = uri.url;
}
console.log("In fetch function", uri, options)
Expand Down
2 changes: 2 additions & 0 deletions JS/wasm/crates/serve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ impl WorkerCtx {
config
.debug_info(true)
.wasm_backtrace(true)
.wasm_threads(true)
.coredump_on_trap(true) // Enable core dumps on trap
.wasm_backtrace_details(WasmBacktraceDetails::Enable);
}
Expand Down Expand Up @@ -189,6 +190,7 @@ impl WorkerCtx {
bindings::io::error::add_to_linker(&mut linker, |x| x).expect("Unable to add io error");
// bindings::sync::io::streams::add_to_linker(&mut linker, |x| x)
// .expect("Unable to add io streams");
bindings::io::poll::add_to_linker(&mut linker, |x| x).expect("Unable to add io poll");
bindings::io::streams::add_to_linker(&mut linker, |x| x).expect("Unable to add io streams");
bindings::cli::stdin::add_to_linker(&mut linker, |x| x).expect("Unable to add cli stdin");
bindings::cli::stdout::add_to_linker(&mut linker, |x| x).expect("Unable to add cli stdout");
Expand Down
23 changes: 20 additions & 3 deletions JS/wasm/examples/axios/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,29 @@ app.get("/", (c) => {
function writeOutput(output) {
const encodedOutput = new TextEncoder().encode(JSON.stringify(output));
const buffer = new Uint8Array(encodedOutput);
writeFileSync(STDIO.Stdout,buffer)
writeFileSync(STDIO.Stdout, buffer)
}

app.get("/axios", async (c) => {
app.get("/get", async (c) => {
console.log("In axios")
let result = await axios.get("https://jsonplaceholder.typicode.com/todos/1");
let result = await axios.get("https://dummy.restapiexample.com/api/v1/employee/1");
let json = result.data;
return c.json(json);
})

app.get("/post", async (c) => {
console.log("post")
// let result = await axios.post("https://dummy.restapiexample.com/api/v1/create", {
// name: "test",
// salary: "123",
// age: "23"
// });
// let json = result.data;
let result = await axios.post("https://jsonplaceholder.typicode.com/posts", {
title: 'foo',
body: 'bar',
userId: 1,
});
let json = result.data;
return c.json(json);
})
Expand Down

0 comments on commit 55786c1

Please sign in to comment.