Skip to content

Quickstart: 5‑Minute Echo API on MARS Engine

Build, deploy, and test your first endpoint without installing anything.


1 . Prerequisites

You needWhy
A modern web browser (Chrome, Firefox, Edge, Safari)MARS Engine runs entirely in‑browser.
A free MARS Engine accountSign up at MARS Engine.

No local Node.js, Git, or database setup required.


2 . Create a new project

  1. Log in to the MARS Engine dashboard.
  2. Click ➕ New Project → choose Blank → name it quickstart.
  3. Wait a few seconds while the workspace spins up (you’ll land in the in‑browser IDE).

3 . Add your first API script

  1. In the File Explorer, click New File.
  2. Enter the path api/echo and 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 msg parameter (param() helper).
  • Writes a JSON key echo with the same value (write()).
  • Runs inside an automatic DB transaction (no action needed here).

Click Save (Ctrl/Cmd + S).


4 . Run & test

  1. In the Run panel (top‑right), press ▶ Run.
    • The Browser opens a new tab which shows https://<workspace‑id>.mars-hosting.com.
  2. 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?

StepBehind the scenes
Request arrivesMARS Engine opens a DB transaction.
param()Reads URL/body/file parameters.
write()Buffers JSON response.
Script endsTransaction auto‑commits and JSON is sent.

6 . Next steps (≤30 min)

  1. Add a database table → by using the Database module from the sidebar.
  2. Query data with db.query('SELECT * FROM ...').
  3. Make it realtime → add ws/chat.js with onMessage.
  4. Generate a PDF using report.pdf() and stream it back.

See: