Autore: Emanuele Della Valle, Matteo Valoriani
Un'applicazione web minimale in nodejs, html e js che dimostra i servizi REST.
Si tratta di un'applicazione client-server basata sul Web.
Il server è un'applicazione node.js che espone i seguenti servizi:
GET /valuerestituisce lo stato del contatore; il valore iniziale è 0GET /inc?n=<valore>aggiungevaloreal contatoreGET /dec?n=<valore>sottraevaloredal contatoreGET /serve la pagina index.html nel folder public all'utente.
Il client è una pagina web HTML 5 che
- richiama il
GET /valueper visualizzare lo stato - offre un campo
inputper consentire all'utente di inserire un numero - offre due pulsanti:
- uno incrementa il contatore del valore presente nel campo di input, chiamando il servizio
GET /inc?n=<value> - l'altro decrementa il contatore chiamando il servizio
GET /dec?n=<valore>.
- uno incrementa il contatore del valore presente nel campo di input, chiamando il servizio
- si auto ricarica ogni secondo
- avere installato Node.js e VSC
- installare express con
npm install express
- lanciare il server dalla cartella
counterin cui c'ècounter.jscon il comandonode counter.js - aprire http://127.0.0.1:3000/ per provare la demo
- pubblicare la vostra applicazione su internet facendo port forward (vedi punto 10 in setup node.js e VSC)
- apri da un altro dispositivo (es. il tuo telefono) l'url del forwarded address
- osserva che puoi cambiare il valore del counter dai due dispositivi
Author: Emanuele Della Valle, Matteo Valoriani
A minimal web application in nodejs, html and js that demonstrates REST services.
This is a web-based client-server application.
The server is a node.js application that exposes the following services:
GET /valuereturns the counter status; the initial value is 0GET /inc?n=<value>addsvalueto the counterGET /dec?n=<value>subtractsvaluefrom the counterGET /serves the index.html page in the public folder to the user.
The client is an HTML 5 web page that
- calls
GET /valueto display the status - offers an
inputfield to allow the user to enter a number - offers two buttons:
- one increments the counter of the value present in the input field, calling the service
GET /inc?n=<value> - the other decreases the counter by calling the service
GET /dec?n=<value>.
- one increments the counter of the value present in the input field, calling the service
- it reloads itself every second
- have Node.js and VSC installed
- install express with
npm install express
- launch the server from the
counterfolder where there iscounter.jswith the commandnode counter.js - open http://127.0.0.1:3000/ to try the demo
- publish your application on the internet by doing a port forward (see point 10 in setup node.js and VSC)
- open the url of the forwarded address from another device (e.g. your phone)
- note that you can change the counter value from both devices