DevPath · Learn to code ESPTEN

Capstone: launch your SaaS

A request's pipeline and the production checklist

The pipeline: validate → authenticate → handle

When a request reaches your API, order matters. A robust handler always processes it in three steps, and stops as soon as something fails:

  1. Validate the input. Are the required fields present? If not, respond 400 Bad Request and stop. There's no point continuing with incomplete data.
  2. Authenticate the caller. Do they bring valid credentials (an authorization header, a token)? If not, respond 401 Unauthorized and stop.
  3. Handle the action: now with good data and a known user, run the logic (read/create/update) and respond with success, e.g. 201 Created.
function handleRequest(req, res, deps) {
  // 1. validate    -> 400 if something is missing
  // 2. authenticate -> 401 if there are no credentials
  // 3. handle      -> use deps to do the work and respond 201
}

Notice that we validate before authenticating: rejecting malformed input is cheap and reveals nothing. The dependencies (the database, the repo) are injected by parameter (deps): this way the handler is easy to test with mocks and isn't tied to a concrete implementation.

Production checklist

"It works on my machine" isn't being ready. Before opening your SaaS to the public, go through a minimal, non-negotiable list:

If anything on that list is missing, you don't launch. You'll build a function that takes the state of each item and says whether you're ready and what's missing. And, since each environment needs different settings (a local DB in dev, a managed one in prod), you'll add a loadConfig(env) that applies default values.

Put this into practice

DevPath is a hands-on course: you read the theory here; in the app you put it into practice with exercises that really run, offline.

Start free in the app →
← The plan: a multi-tenant SaaSView the module →