Appearance
Quickstart: 5‑Minute Echo API on MARS Engine
Build, deploy, and test your first endpoint without installing anything.
1 . Prerequisites
| You need | Why |
|---|---|
| A modern web browser (Chrome, Firefox, Edge, Safari) | MARS Engine runs entirely in‑browser. |
| A free MARS Engine account | Sign up at MARS Engine. |
No local Node.js, Git, or database setup required.
2 . Create a new project
- Log in to the MARS Engine dashboard.
- Click ➕ New Project → choose Blank → name it
quickstart. - Wait a few seconds while the workspace spins up (you’ll land in the in‑browser IDE).
3 . Add your first API script
- In the File Explorer, click New File.
- Enter the path
api/echoand paste the code below:
js
// api/echo
/**
* Simple echo endpoint.
* GET /api/echo?msg=Hello
*/
const message = param('msg', 'Hello from MARS Engine!');
write('echo', message);This script:
- Reads the
msgparameter (param()helper). - Writes a JSON key
echowith the same value (write()). - Runs inside an automatic DB transaction (no action needed here).
Click Save (Ctrl/Cmd + S).
4 . Run & test
- In the Run panel (top‑right), press ▶ Run.
- The Browser opens a new tab which shows
https://<workspace‑id>.mars-hosting.com.
- The Browser opens a new tab which shows
- Open a terminal and curl the endpoint (replace
<workspace‑id>):
bash
curl "https://<workspace-id>.mars-hosting.com/api/echo?msg=Hello"You should see:
json
{ "echo": "Hello" }or, without a query param:
bash
curl https://<workspace-id>.mars-hosting.com/api/echo
# → { "echo": "Hello from MARS Engine!" }5 . What just happened?
| Step | Behind the scenes |
|---|---|
| Request arrives | MARS Engine opens a DB transaction. |
param() | Reads URL/body/file parameters. |
write() | Buffers JSON response. |
| Script ends | Transaction auto‑commits and JSON is sent. |
6 . Next steps (≤30 min)
- Add a database table → by using the Database module from the sidebar.
- Query data with
db.query('SELECT * FROM ...'). - Make it realtime → add
ws/chat.jswithonMessage. - Generate a PDF using
report.pdf()and stream it back.
See:
- Concepts/Request lifecycle – deep dive on transactions