DEV Community

Edgar Rios Navarro
Edgar Rios Navarro

Posted on

1 1

Demo ElectronJS y API REST

Crear aplicaciones de escritorio nativas, siempre fue una especialización: Windows/VB, Linux/Qt o Mac/Objective-C.

Con el crecimiento del Internet, las empresas migraron muchas de sus aplicaciones hacia la Web2. ¡Ni qué decir de la era del smartphone!

En ese contexto, varios proyectos trataron de aprovechar los conocimientos y tecnologías web; para construir programas de escritorio. Por ejemplo: JavaFX, Electron, Tauri, etc.

Electron tiene buena popularidad, tanto que VSCode está construido sobre él.


Presentamos el código para invocar un API REST, usando Javascript.

let newBook = {
title: "New book from Electron",
pages: 350
};
postData('http://localhost:8080/books', newBook)
.then(data => {
console.log(data); // JSON data parsed by `data.json()` call
});
view raw index-add.js hosted with ❤ by GitHub
fetch(`http://localhost:8080/books`)
.then(res => {
console.log(res.status)
return res.json()
})
.then(data => {
// remove rows
var myData = document.getElementById('myData');
myData.innerHTML = "";
for(i in data) {
var row = myData.insertRow();
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
cell1.innerHTML = data[i].id;
cell2.innerHTML = data[i].title;
cell3.innerHTML = data[i].pages;
}
}).catch(err => console.log(err))

Y para maquetar la grilla, se emplea HTML y CSS.

Image description

Image description


Documentación

https://www.electronjs.org/

GitHub logo edgargs / my-electron-app

Electron app as client REST

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Bump.sh

Hate writing docs?

Hate undocumented APIs even more?

Bump.sh generates an always up-to-date API reference site for REST and Event-Driven Architectures.

Plug it in your CI. It fetches your OpenAPI and AsyncAPI (GraphQL pending) spec files, and even generates a diff. Gather all of your API docs in a single source of truth.

Try it for free

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay