Inputs & Outputs
Handle path parameters, query strings, request bodies, and configure API responses.
Inputs & Outputs
Your endpoints receive data from requests and send back responses. Define the inputs an endpoint expects, attach a function, then use those values from the function steps.
The endpoint editor showing input and output configuration Configure inputs and outputs in the endpoint editor
Inputs
When a request arrives, Spala makes the data available through built-in variables:
Path parameters (params)
Dynamic segments in the URL path:
// Endpoint: GET /api/cases/:id // Request: GET /api/cases/42
params.id // "42"
Query string (query)
Key-value pairs after the ? in the URL:
// Request: GET /api/cases?page=2&limit=10
query.page // "2" query.limit // "10"
Good to know
Query string and path parameter values are always strings. Convert them with query.page | toNumber when you need a number.
Request body (input)
The JSON body for POST, PUT, and PATCH requests:
// Request: POST /api/cases
// Body: { "case_name": "Contract Review", "status": "open" }
input.case_name // "Contract Review" input.status // "open"
Headers (headers)
HTTP headers sent with the request:
headers.authorization // "Bearer eyJhbG..." headers['content-type'] // "application/json"
File inputs
For upload endpoints, add a file input in the endpoint editor and use the generated input in the attached function. This keeps the Playground, generated docs, and implementation in sync.
Outputs
Use a Return step in your function to set the response:
// Return data with a 200 status Value: vars.cases Status: 200
// Return an error with a 404 status
Value: { error: "Case not found" }
Status: 404
// Return a created resource with 201 Value: vars.newCase Status: 201
Common status codes
| Code | Meaning | When to use | |------|------------------|------------------------------------| | 200 | OK | Successful read or update | | 201 | Created | Successfully created a resource | | 400 | Bad Request | Missing or invalid input | | 401 | Unauthorized | Missing or bad authentication | | 404 | Not Found | Resource does not exist | | 500 | Server Error | Something went wrong |
Create an Endpoint /endpoints/creating-endpoints Set up your endpoints API Docs /features/api-docs Share endpoint inputs and responses Protect Your Endpoints /endpoints/authentication Add authentication