WASDEV(The AI WorkShop)Docs Website Download

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">
The page built by GAD, opened in the WASDEV browser
The page built by GAD, opened in the WASDEV browser
  1. Open the file in the editor.
  2. Open the Run menu and choose GAD: Build for web.
  3. Open the file index.html that 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
The server running in the WASDEV terminal, with one line per request
The server running in the WASDEV terminal, with one line per request
  1. Create the file sèvè.gad with this code.
  2. Press F5, or type gad kouri sèvè.gad in the terminal.
  3. Send requests to http://localhost:8787. The terminal writes one line per request.
  4. Press Ctrl+C in 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 its id.
  • reponn with a dictionary or a list answers JSON. With a text, it answers text.
  • --pò 9000 listens on another port. --piblik lets 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.