
Chapter 1 · GAD language
Web pages and servers
The same interface code becomes a static web page, and a few lines make an HTTP server with a database.
The same code as a web page
sèvi ak vizyon
<legba>
<fenèt tit="GRAN LAKU">
<kad sant lajè=760>
<meni>
<tèks tèks="Akèy">
<tèks tèks="Sèvis">
<tit tèks="Nou bati zouti an Kreyòl" parèt>
<seksyon>
<tèks tèks="Yon sèl kòd pou tout kote." monte>
<ranje>
<bouton id="kòmanse" tèks="Kòmanse">
<bouton id="aprann" tèks="Aprann plis">
<pye>
<tèks tèks="GRAN LAKU COMPANY">

- Open the file in the editor.
- Open the Run menu and choose GAD: Build for web.
- Open the file
index.htmlthat GAD wrote.
GAD WEB AP bati.
gwosè : 4010 oktè
JavaScript : 0 liy
lòt fichye : robots.txt
- Not one line changes between the window and the web page.
- The page stands alone: no JavaScript when the page is not interactive, no CDN, no font from the internet.
- A button that depends on a state needs a server: a static page has no memory, and GAD says which buttons do not answer.
- Typed in the terminal:
gad bati sit.gad pou web --sòti soti/web.
A server with a database
Three keywords make a server: wout, reponn and sèvè. depo keeps the records in a folder next to the program, with no configuration.
sèvi ak simbi
sèvi ak depo
wout GET "/bonjou"
reponn 200 ak { mesaj: "Bonjou" }
fini
wout POST "/api/kont"
done = demann.json
si done.non vid
reponn 400 ak { erè: "Non an obligatwa." }
fini
reponn 201 ak depo.kreye("kont", done)
fini
wout GET "/api/kont"
reponn 200 ak depo.tout("kont")
fini
sèvè sou pò 8787

- Create the file
sèvè.gadwith this code. - Press
F5, or typegad kouri sèvè.gadin the terminal. - Send requests to
http://localhost:8787. The terminal writes one line per request. - Press
Ctrl+Cin the terminal to stop the server.
GAD SÈVÈ ap koute sou http://127.0.0.1:8787
POST /api/kont 201 35 oktè 1.8 ms
GET /api/kont 200 37 oktè 0.2 ms
- The answer to the POST request was
{"balans":150,"id":1,"non":"Ayiti"}: the database gave the record itsid. reponnwith a dictionary or a list answers JSON. With a text, it answers text.--pò 9000listens on another port.--pibliklets another machine on the network reach the server.- An error in a route does not stop the server: the client receives a 500 with the message.
