Код JavaScript:
Код: Выделить всё
import axios from "axios";
const API_URL = "https://jsonplaceholder.typicode.com/posts";
const fetchPosts = async () => {
try {
const response = await axios.get(API_URL);
console.log("Posts:", response.data);
} catch (error) {
console.error("Error fetching posts:", error);
}
};
// Call the function
fetchPosts();
Связанный JavaScript с использованием es Bundle
Код Java для выполнения связанного кода ES:
Код: Выделить всё
public static void main( String[] args )
{
String jscode = null;
try {
jscode = new String(Files.readAllBytes(Paths.get("/tmp/main.js")));
} catch (IOException e) {
throw new RuntimeException(e);
}
try (Context context = Context.create()) {
Value value = context.eval("js", jscode);
value.execute();
}
}
Код: Выделить всё
UTF-8
24.1.1
org.graalvm.polyglot
polyglot
${graaljs.version}
org.graalvm.polyglot
js
${graaljs.version}
pom
org.graalvm.polyglot
tools
${graaljs.version}
pom
junit
junit
3.8.1
test
Код: Выделить всё
Error fetching posts: AxiosError: There is no suitable adapter to dispatch the request since :
adapter xhr is not supported by the environment
adapter http is not available in the build
adapter fetch is not supported by the environment
Заранее спасибо !
Подробнее здесь: https://stackoverflow.com/questions/793 ... using-java