BigWeb (The Server Engine)
BigWeb allows you to turn your BigC script into a web server that hosts websites and APIs.
1. Unlocking the Engine
You must tell the engine you want to use web features at the top of your file.
use web
2. Server Configuration
You can control the server's behavior, such as limiting the number of requests to prevent overload.
Syntax: control limit [Number] per mins
# Allow only 60 requests per minute
control limit 60 per mins
3. Setting Rules (Routing)
In BigWeb, you map a URL (like /home) to a Chapter. When someone visits that URL, the Chapter runs.
Syntax: on [GET/POST] "[Path]" run [ChapterName]
on get "/" run HomeChapter
on post "/login" run LoginChapter
4. Handling Requests
Inside your chapter, you can access data sent by the user.
take body & set as {Data}: Gets the raw text sent in a POST request.RequestPath: A variable containing the URL.RequestMethod: A variable containing "GET" or "POST".
5. Sending Replies
Every chapter must send a reply to the browser.
reply with "Hello": Sends plain text.reply with "<h1>$Title</h1>": Sends HTML content (variables allowed).reply file "page.html": Sends a static HTML file. (No variable interpolation).reply file "layout.Hbig": Sends a BigC Layout file. (No variable interpolation).
6. Starting the Server
The final command in your script should start the listener.
Syntax: start server at [Port]
start server at 8080
7. Layouts (.Hbig) & Styles (.Bcss)
Hbig is the "Toddler's HTML", and Bcss is the "Toddler's CSS".
Example home.Hbig:
box class "main"
header "Welcome"
text "This is BigC Web."
button "Click Me"
end box
Example home.Bcss:
style "main"
background white
padding 20
center
end style
(The engine automatically combines home.Hbig and home.Bcss when you reply with the file.)