arkynChangelogGuides
docs / success-responses / found

Found

The Found class represents a successful HTTP response with status code 302. It is used to standardize "Found" responses, where the requested resource was located and is included directly in the response body.

Import

ts

import { Found } from "@arkyn/server/found";
Learn how subpath and root imports differ in How do I use imports.

Constructor

  • message (required): A message describing the status.
  • body (optional): The response body to include in the HTTP response, which can be any serializable data. This is where the found resource itself is typically included.

Methods

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.

Usage example

typescript

import { Found } from "@arkyn/server/found";
// Basic usage - return the response
const response = new Found("Resource located");
return response.toResponse();
// With the found resource in the body
return new Found("Products retrieved", {
products,
}).toResponse();
// Using toJson alternative
return new Found("User located", {
user,
}).toJson();

Response structure

The response body contains the data passed to the constructor:

json

{
"products": []
}

Notes

When instantiated, this class automatically emits a debug log to the console showing the file and function where it was created. See DebugService to configure ignored files for accurate caller detection.
The body parameter is optional. If not provided, the response body will be undefined.
Note: this response does not set a Location header, it returns the found resource directly in the JSON body with a 302 status, rather than performing a browser-level redirect.
Common use cases include returning a resource that was found via a lookup or search operation, using a distinct status code (302) from a standard Success (200) response.
Related in Success Responses
On this page
    arkyn