API Responses
> Choose what your routes return -- JSON data, HTML pages, status codes, or custom content types.
Every route needs to end with a return node that sends a response back to the caller. Brickr provides several return nodes for different response types.
Return JSON
The Return JSON node sends a JSON response. This is the most common return type for APIs.
| Input | Type | Description | |-------|------|-------------| | json | Object | The data to return | | statusCode | Enum | HTTP status code |
// Example response
{ "message": "User created", "id": "abc123" }
Return Status
The Return Status node sends an HTTP status code with an optional text message. Use it for simple success/error responses.
| Input | Type | Description | |-------|------|-------------| | message | String | Optional response message | | statusCode | Enum | HTTP status code |
Return HTML
The Return HTML node sends an HTML string as the response. Use it when you have raw HTML content.
| Input | Type | Description | |-------|------|-------------| | html | String | HTML content | | statusCode | Enum | HTTP status code | | contentType | Enum | Content type header |
Return Website
The Return Website node renders web element nodes as an HTML page. Use it with Web Elements to build pages visually.
Available status codes
All return nodes support these HTTP status codes:
| Code | Name | When to use | |------|------|-------------| | 200 | OK | Successful request (default) | | 201 | Created | A new resource was created | | 204 | No Content | Success with no response body | | 400 | Bad Request | Invalid input from the caller | | 401 | Unauthorized | Missing or invalid authentication | | 403 | Forbidden | Authenticated but not allowed | | 404 | Not Found | Resource does not exist | | 500 | Internal Server Error | Something went wrong |
Content types
The Return HTML node supports these content types:
| Content Type | Use case | |--------------|----------| | application/json | JSON data (default for Return JSON) | | text/html | HTML pages | | text/plain | Plain text | | application/xml | XML data | | application/x-www-form-urlencoded | Form data |
Example: Different responses based on input
Use a Switch or If node to return different responses depending on the request:
1. Start Node receives the request. 2. Get Property extracts a value from the request body. 3. If checks a condition. 4. True branch > Return JSON with status 200 and success data. 5. False branch > Return JSON with status 400 and an error message.
Always return meaningful error messages with appropriate status codes. This makes your API easier to use and debug for callers.
What's next?
| Topic | Description | |-------|-------------| | Authentication | Protect your routes | | Parameters | Access request data | | Web Elements | Build HTML responses visually |