Serverless API handler

A code exercise of about 20 minutes: read the statement, solve «Serverless API handler» in the browser and get a review like in a real interview.

Code · 20 min
Loading…

Statement

Write handler(event) for a serverless function behind API Gateway (HTTP API). Only POST is accepted: any other method → 405. The body is JSON with sku (non-empty string) and qty (integer ≥ 1). Invalid JSON → 400; invalid fields → 422 with { errors: [...] } listing the fields ("sku", "qty"). Otherwise → 201 with { id: "ord_" + sku, sku, qty }. Always return { statusCode, body } with body as a JSON string.