Success class represents a successful HTTP response with status code 200. It is used to standardize "OK" success responses, typically for GET requests or operations that return data.ts
import { Success } from "@arkyn/server";
message (required): A message describing the operation status.body (optional): The response body to include in the HTTP response, which can be any serializable data. This is useful for returning data to the client or providing additional information about the successful operation.toResponse() - Converts the instance into a Response object with JSON body and Content-Type: application/json header.toJson() - Alternative method using Response.json() for generating the JSON response.typescript
import { Success } from "@arkyn/server";// Basic usage - return the responseconst response = new Success("Operation completed");return response.toResponse();// With response bodyconst users = [{ id: "1", name: "John" },{ id: "2", name: "Jane" },];return new Success("Users retrieved successfully", users).toResponse();// With additional data (e.g., closeModal flag for frontend)return new Success("Settings saved", {closeModal: true,settings: { theme: "dark", language: "en" },}).toJson();
json
{"closeModal": true,"settings": {"theme": "dark","language": "en"}}
body parameter is optional. If not provided, the response body will be undefined.