Hand this to a coding agent before it writes SudoMock calls in Express.
Prerequisites
- Node 20 or later, with Express 4 or 5. The files below are ESM, so set
"type": "module"in yourpackage.json. A CommonJS project can reach the same client withconst { SudoMock } = require('sudomock'). - An API key. Create one, then export it. Keys begin
with
sm_and travel in thex-api-keyheader. - A PSD reachable over HTTPS. Preparing a PSD covers what to check before the first upload.
- Render with Node.js if you want the same two calls without a framework around them.
Guide
1
Install
SUDOMOCK_API_KEY when you construct it with no argument.2
Upload the template once
Uploading returns the layers you can address later, each with its own
UUID. This belongs in a setup script, not in the path that serves
requests.Run it, then keep the two UUIDs it prints:
upload.js
3
Add the render route
Keep the render in its own router, so the server file stays about wiring.
The handler reads the artwork URL, answers Now mount it.
400 when it is missing, and
hands anything the API raises to the error middleware. It reads the body
through ?? {}, because Express 5 leaves req.body undefined when a
request arrives without JSON, and the check answers 400 either way.routes/mockups.js
express.json() has to run before the route, or req.body
is undefined by the time the handler reads it.server.js
express.json() accepts 100kb by default, which is room enough for an
artwork URL. Raise its limit if you accept artwork inline as base64
instead.4
Answer the failures in one place
Everything the client raises is a The answer carries
SudoMockError carrying status and
code, so a single middleware covers every route that renders. It is the
last thing mounted and it takes four arguments, which is how Express
tells an error handler from an ordinary one.Express 4 does not hand a rejected promise to that middleware, which is
why the handler calls next(error) itself. Express 5 forwards it, and
the explicit call is correct on both.A client side failure, such as a timed out connection, reports status
as 0. Sending that straight back would answer with a status no client
understands, so the middleware falls back to 502.Start the server and send it an artwork:url, the finished image. How the artwork meets the
smart object is set by asset.fit, described in
Fit and blend modes.Error codes lists every code, its status, and whether
retrying it can help.Next steps
Webhooks
Give a background render its own Express route to report back to.
SDK reference
Every resource on the client, in Node and in Python.