-
This question was originally asked by @gnahraf, but transferred here from another discussion. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 6 replies
-
Here is what we have so far to communicate with servers: a cross-platform Web Socket API for the low level, and a cross-platform EventBus + JSON API for the high level (which is the preferred communication protocol for modern servers such as Vert.x or Spring Boot). But I guess you just want to do a simple HTTP request? We don't presently have this API, but it shouldn't be that difficult to make. What type of data are you expecting for the result? Will you be happy with a API that just returns the result as a String? As I said, we have a cross-platform JSON API, so you can use it to parse the result if this is the format you expect. But we don't have a cross-platform XML API. |
Beta Was this translation helpful? Give feedback.
-
Yes. My REST endpoints are straight HTTP/HTTPS for now (user sessions are short lived) |
Beta Was this translation helpful? Give feedback.
-
hi @gnahraf, I published the first version of the Fetch API in the WebFX Platform! Here is how to include it in your project:
Here are a few use-cases of the Fetch API (if not yet imported, use the fully qualify class
Fetch.fetch("https://jsonplaceholder.typicode.com/posts/1")
.onFailure(error -> Console.log("Fetch failure: " + error))
.onSuccess(response -> {
Console.log("Fetch success: ok = " + response.ok());
response.text()
.onFailure(error -> Console.log("Text failure: " + error))
.onSuccess(text -> Console.log("Text Success: " + text));
});
Fetch.fetch("https://jsonplaceholder.typicode.com/posts/1") // Expecting a JSON object only
.onFailure(error -> Console.log("Fetch failure: " + error))
.onSuccess(response -> {
Console.log("Fetch success: ok = " + response.ok());
response.jsonObject()
.onFailure(error -> Console.log("JsonObject failure: " + error))
.onSuccess(jsonObject -> {
Console.log("JsonObject Success: " + jsonObject.toJsonString());
Console.logNative(jsonObject); // Will display a browsable JSON object in the browser console
});
});
Fetch.fetch("https://jsonplaceholder.typicode.com/posts") // // Expecting a JSON array only
.onFailure(error -> Console.log("Fetch failure: " + error))
.onSuccess(response -> {
Console.log("Fetch success: ok = " + response.ok());
response.jsonArray()
.onFailure(error -> Console.log("JsonArray failure: " + error))
.onSuccess(jsonArray -> {
Console.log("JsonArray Success: " + jsonArray.toJsonString());
Console.logNative(jsonArray); // Will display a browsable JSON array in the browser console
});
});
Fetch.fetch("https://jsonplaceholder.typicode.com/posts") // Expecting a JSON object or array
.onFailure(error -> Console.log("Fetch failure: " + error))
.onSuccess(response -> {
Console.log("Fetch success: ok = " + response.ok());
response.json()
.onFailure(error -> Console.log("Json failure: " + error))
.onSuccess(json -> {
if (json.isObject()) {
JsonObject jsonObject = json.asJsonObject();
Console.log("JsonObject Success: " + jsonObject.toJsonString());
Console.logNative(jsonObject); // Will display a browsable JSON object in the browser console
} else if (json.isArray()) {
JsonArray jsonArray = json.asJsonArray();
Console.log("JsonArray Success: " + jsonArray.toJsonString());
Console.logNative(jsonArray); // Will display a browsable JSON array in the browser console
}
});
}); Let me know if this works for you, or if you need another use-case. |
Beta Was this translation helpful? Give feedback.
-
Thank you Bruno.
I've been meaning to respond after I try it but have been busy with another
deliverable. I'll definitely try it after and loop back with you. Prolly
next week. Apologies for the delayed response.
Babak
…On Wed, Nov 2, 2022 at 9:56 AM Bruno Salmon ***@***.***> wrote:
hi @gnahraf <https://github.com/gnahraf>, I published the first version
of the Fetch API in the WebFX Platform. Here is how to include it in your
project:
1. Type webfx bump cli in the terminal to update your CLI to the
latest version
2. Add import dev.webfx.platform.fetch.Fetch; in your class (or use
the fully qualified class dev.webfx.platform.fetch.Fetch somewhere in
your code)
3. Type webfx update --clean-snapshots (or short syntax: webfx update
-c) at your project root directory (this new --clean-snapshots option
should prevent the problem you had last time with old snapshots in your
local Maven repository)
Here are a few use-cases of the Fetch API (if not yet imported, use the
fully qualify class dev.webfx.platform.console.Console, and the webfx
update command should import it, then you can replace the fully qualify
class with an import):
1. Fetching a text:
Fetch.fetch("https://jsonplaceholder.typicode.com/posts/1")
.onFailure(error -> Console.log("Fetch failure: " + error))
.onSuccess(response -> {
Console.log("Fetch success: ok = " + response.ok());
response.text()
.onFailure(error -> Console.log("Text failure: " + error))
.onSuccess(text -> Console.log("Text Success: " + text));
});
1. Fetching a JSON object:
Fetch.fetch("https://jsonplaceholder.typicode.com/posts/1") // Expecting a JSON object only
.onFailure(error -> Console.log("Fetch failure: " + error))
.onSuccess(response -> {
Console.log("Fetch success: ok = " + response.ok());
response.jsonObject()
.onFailure(error -> Console.log("JsonObject failure: " + error))
.onSuccess(jsonObject -> {
Console.log("JsonObject Success: " + jsonObject.toJsonString());
Console.logNative(jsonObject); // Will display a browsable JSON object in the browser console
});
});
1. Fetching a JSON array:
Fetch.fetch("https://jsonplaceholder.typicode.com/posts") // // Expecting a JSON array only
.onFailure(error -> Console.log("Fetch failure: " + error))
.onSuccess(response -> {
Console.log("Fetch success: ok = " + response.ok());
response.jsonArray()
.onFailure(error -> Console.log("JsonArray failure: " + error))
.onSuccess(jsonArray -> {
Console.log("JsonArray Success: " + jsonArray.toJsonString());
Console.logNative(jsonArray); // Will display a browsable JSON array in the browser console
});
});
1. Fetching a JSON object or array (if you don't know which one to
expect in advance):
Fetch.fetch("https://jsonplaceholder.typicode.com/posts") // Expecting a JSON object or array
.onFailure(error -> Console.log("Fetch failure: " + error))
.onSuccess(response -> {
Console.log("Fetch success: ok = " + response.ok());
response.json()
.onFailure(error -> Console.log("Json failure: " + error))
.onSuccess(json -> {
if (json.isObject()) {
JsonObject jsonObject = json.asJsonObject();
Console.log("JsonObject Success: " + jsonObject.toJsonString());
Console.logNative(jsonObject); // Will display a browsable JSON object in the browser console
} else if (json.isArray()) {
JsonArray jsonArray = json.asJsonArray();
Console.log("JsonArray Success: " + jsonArray.toJsonString());
Console.logNative(jsonArray); // Will display a browsable JSON array in the browser console
}
});
});
Let me know if this works for you, or if you need another use-case.
—
Reply to this email directly, view it on GitHub
<#15 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABHUG6J4VDY4FMRLPHSDGXLWGKFJPANCNFSM6AAAAAARKPQKEU>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
hi @gnahraf, I published the first version of the Fetch API in the WebFX Platform! Here is how to include it in your project:
webfx bump cli
in the terminal to update your CLI to the latest versionimport dev.webfx.platform.fetch.Fetch;
in your class (or use the fully qualified classdev.webfx.platform.fetch.Fetch
somewhere in your code)webfx update --clean-snapshots
(or short syntax:webfx update -c
) at your project root directory (this new--clean-snapshots
option should prevent the problem you had last time with old snapshots in your local Maven repository)Here are a few use-cases of the Fetch API (if not yet imported, use the fully qualify class
dev.webfx.platform.co…