Appearance
Hello MARS Engine Tour
Welcome to MARS Engine!
This lightning‑tour walks you through building and testing the classic “Hello, World!” API, while showing off a few MARS super‑powers.
1 Create a new project
- Log in to your MARS workspace and click ➕ New Project.
- Pick a name (e.g.
hello‑world‑tour) and hit Create.
Your project appears with an empty filesystem to the left.
Right click in the filesystem area, Add new folder, name it api and press Enter to create the folder.
2 Add your first API file
- Right‑click api ▸ New File ▸ API.
- Name it hello (the extension doesn’t matter).
Paste the snippet below and press Ctrl + S to save.
js
// /api/hello
write('message', 'Hello, World!'); // 👋 simplest possible responseWhat just happened?
write()is MARS’ universal output function.
With two arguments write(key, value) builds a JSON response:json{ "message": "Hello, World!" }Every API file runs inside an implicit transaction and auto‑commits when it finishes without errors.
3 Run the API
Click the ▶︎ Run button (or open http(s)://<your‑host>/api/hello) and you should see:
json
{ "message": "Hello, World!" }4 Personalise with param()
Let’s greet the caller by name:
js
// /api/hello
const name = param('name', 'World'); // fallback if not supplied
write('message', `Hello, ${name}!`);Call /api/hello?name=Alex → { "message": "Hello, Alex!" }
param()fetches parameters no matter how they were sent
(query‑string, JSON body, form‑data, etc.).- The second argument is an optional default.
5 Plain‑text output & custom headers
js
header('content-type', 'text/plain'); // must come before write()
write(param('name', 'World'));Now /api/hello returns raw text/plain.
6 Persist greetings in the database
js
const name = param('name', 'World');
db.query(
'INSERT INTO greetings (gre_name) VALUES (?)',
name
);
write('status', 'OK');db.query()runs prepared statements automatically.- Return‑value is an array-see Query object in the docs for details.
7 Quick extras
| Feature | One‑liner | Docs |
|---|---|---|
| Abort early | exit(); | Terminate execution |
| Hash a password | const hash = bcrypt(pass); | Bcrypt |
| WebSocket | File type WebSocket with onMessage() | WebSockets |
8 Next steps
- Explore Input, Output, Database, and Sessions sections in the left sidebar.
- Clone this project and add authentication, validation, or Firebase push notifications.
- Join the community forum if you get stuck- we’re friendly!
Happy coding with MARS Engine 🚀