diff --git a/.changeset/two-hairs-notice.md b/.changeset/two-hairs-notice.md new file mode 100644 index 000000000..6e99c5af6 --- /dev/null +++ b/.changeset/two-hairs-notice.md @@ -0,0 +1,5 @@ +--- +"docs": patch +--- + +docs: render frame nextjs api docs diff --git a/docs/pages/reference/render/next/get.mdx b/docs/pages/reference/render/next/get.mdx index b6dabd9fd..b5071b077 100644 --- a/docs/pages/reference/render/next/get.mdx +++ b/docs/pages/reference/render/next/get.mdx @@ -1,7 +1,34 @@ # GET +Fetches HTML content from a given URL and attempts to extract a frame from it. + ## Usage ```tsx [./frames/route.tsx] export { GET, POST } from "@frames.js/render/next'; ``` + +### Request + +- **URL Query Parameters:** + - `url` (required): The URL from which the HTML content is to be fetched. + +### Response + +Depending on the outcome of the fetch and frame extraction process, the response can vary: + +- **Success:** + - Returns a JSON object containing the extracted frame data and any errors encountered during the frame extraction process. +- **Invalid URL:** + + - If the `url` parameter is missing or invalid, returns a JSON object with a `message` indicating "Invalid URL" and a status code of 400. + +- **Fetch or Processing Errors:** + - In case of errors during the fetch operation or frame extraction, returns a JSON object with a `message` detailing the error and a status code of 500. + +### Errors + +Errors are communicated through the status codes and messages in the JSON response: + +- **400 Bad Request:** Indicates that the required `url` query parameter is missing or invalid. +- **500 Internal Server Error:** Indicates an error during the fetch operation or while processing the fetched content. diff --git a/docs/pages/reference/render/next/post.mdx b/docs/pages/reference/render/next/post.mdx index d372a38fb..978a256f1 100644 --- a/docs/pages/reference/render/next/post.mdx +++ b/docs/pages/reference/render/next/post.mdx @@ -1,7 +1,39 @@ # POST +Proxies a POST request to the specified `postUrl` with the payload provided in the request body. + ## Usage ```tsx [./frames/route.tsx] export { GET, POST } from "@frames.js/render/next'; ``` + +### Request + +- **URL Query Parameters:** + + - `postType` (optional): A string indicating the type of the POST request. It can be either `post_redirect` to handle redirects manually or `tx` for transaction requests. + - `postUrl` (required): The URL to which the POST request should be proxied. + +- **Body:** JSON payload conforming to the `FrameActionPayload` structure imported from `frames.js`. + +### Response + +The response varies depending on the `postType` and the status of the request to the `postUrl`. + +- **For a 302 status code from `postUrl`:** + + - Returns a JSON object containing the `location` header value from the response, with a status code of 302. + +- **For `postType` of `tx`:** + + - Returns the JSON response received from the `postUrl`. + +- **For other responses:** + - Attempts to extract a frame from the HTML content returned by the `postUrl`, using the `getFrame` function from `frames.js`. Returns a JSON object containing the frame data and any errors encountered during the frame extraction process. + +### Errors + +- Returns a response generated by `Response.error()` in case of: + - Absence of the `postUrl` parameter in the request. + - Any fetch operation or processing errors.