Created class represents a successful HTTP response with status code 201. It is used to standardize "Created" success responses, typically when a new resource has been successfully created.ts
import { Created } from "@arkyn/server";
message (required): A message describing the creation status.body (optional): The response body to include in the HTTP response, which can be any serializable data. This is useful for returning the created resource or additional information to the client.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 { Created } from "@arkyn/server";// Basic usage - return the responseconst response = new Created("User created successfully");return response.toResponse();// With response bodyconst newUser = { id: "123", name: "John", email: "john@example.com" };return new Created("User created successfully", newUser).toResponse();// With additional data (e.g., closeModal flag for frontend)return new Created("Product added to catalog", {closeModal: true,product: { id: "456", name: "New Product" },}).toJson();
json
{"closeModal": true,"product": {"id": "456","name": "New Product"}}
body parameter is optional. If not provided, the response body will be undefined.