Skip to content

feat(studio): Global REST API Console with auto-discovery#892

Merged
hotlong merged 5 commits into
mainfrom
copilot/add-global-rest-api-console
Mar 9, 2026
Merged

feat(studio): Global REST API Console with auto-discovery#892
hotlong merged 5 commits into
mainfrom
copilot/add-global-rest-api-console

Conversation

Copilot AI commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

Studio's ObjectApiConsole only tests CRUD for a single object with hardcoded endpoints. This adds a top-level API Console that auto-discovers all registered REST APIs from platform metadata.

New files

  • src/hooks/use-api-discovery.ts — Hook that queries client.meta.getTypes() and client.meta.getItems() to dynamically build the full endpoint tree (CRUD per object + system/auth/metadata endpoints), grouped and sorted by category
  • src/components/ApiConsolePage.tsx — Three-panel console: collapsible endpoint tree with search/filter, request editor (method selector, URL bar, JSON body), form-based query parameter editor, response viewer with status/timing/copy/history/replay
  • test/api-discovery.test.ts — 5 tests covering object discovery, endpoint generation, grouping logic, idempotent re-discovery, and query param URL building

Modified files

  • App.tsx — Added 'api-console' to ViewType union and view routing
  • app-sidebar.tsx — "API Console" entry under System section
  • site-header.tsx — Breadcrumb support for api-console view
  • ROADMAP.md — Marked Global REST API Console as complete

Key design decisions

  • Endpoints refresh on demand via refresh() — no polling, no stale cache
  • Object add/delete is reflected by re-running discovery against live metadata
  • Reuses the same fetch + (client as any).baseUrl pattern from existing ObjectApiConsole
  • History kept in-memory (50 entries), with one-click replay
  • Form-based query parameter editor with add/remove rows, enable/disable toggle per param, OData preset quick-add buttons ($top, $skip, $sort, $select, $count, $filter), and live URL preview showing the full path with appended query string
  • History replay restores query params back into the form table
Original prompt

This section details on the original issue you should resolve

<issue_title>Studio 全局 REST API 控制台:自动发现和测试所有 API</issue_title>
<issue_description>

背景

当前 Studio 的 ObjectApiConsole 只针对单一 Object 提供 CRUD 测试,无法方便浏览和测试所有 REST API(包括自定义、批量、元数据等)。随着服务逐渐丰富,API数目变多,开发/测试/集成场景需要一站式、高效的"API 控制台"。

目标

实现一个"全局 REST API 控制台",在 Studio 顶级面板提供:

  • 自动发现所有已注册的 REST API(Discovery + Meta + Registry)
  • 支持分组浏览(如 Data、Metadata、Batch、Auth…),端点树可折叠/搜索/过滤
  • 一键填充 method/path/BodyTemplate,快捷编辑并发起请求
  • 响应高亮展示(状态/时间/Body)与完整请求历史,支持重放
  • 动态 Object 新增/删除后端点自动刷新,不需手写
  • 支持 Query Params/Table(OData/数据分页等)表单化填写
  • 自动继承平台认证,保障安全

推荐实现路径

  1. 新增 ApiConsolePage,作为 Studio 顶级入口,支持独立路由
  2. 新增 ApiConsole/ 组件(EndpointTree + RequestPanel + ResponsePanel + useApiDiscovery),实现左侧分组树+中间请求+右侧响应
  3. 端点来源:基础 Discovery /api/v1/discovery + Metadata /api/v1/meta/object,可结合 Registry API/Meta数据完善
  4. 复用旧 ObjectApiConsole 的 send/history 逻辑,扩展为全局多 API
  5. UX:分组/折叠/搜索/快速切换,表单式填写参数与 Body(JSON Schema 自动生成可升级为 phase2)
  6. 支持多环境/变量(预留后续能力),初期以 studio session auth/context 为主

补充

  • 中长期目标可参考 Postman、Hoppscotch、Swagger UI,但重点保持 ObjectStack Studio 风格一体化
  • 若未来支持 OpenAPI/自定义文档,可接口 Registry/Meta 自动生成(phase2)

Done Criteria

  • Studio 顶级 API 控制台可自动发现所有 REST API,分组浏览,搜索测试
  • 用户无需手写端点,任意 Object 增删自动刷新、端点自动出现
  • 支持请求/响应查看、历史记录、基本参数/Body表单化填写

完成后请:

  • 更新 ROADMAP.md 标记相关 deliverable
  • 增强自动测试覆盖
  • 关联所有相关 API/Studio/Registry/Meta issues

如需后续支持 GraphQL/WebSocket/Batch/SwaggerUI集成/收藏夹,请在此 issue 下讨论扩展方案。
</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@vercel

vercel Bot commented Mar 9, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
objectstack-play Ready Ready Preview, Comment Mar 9, 2026 10:39am
spec Ready Ready Preview, Comment Mar 9, 2026 10:39am

Request Review

Copilot AI and others added 2 commits March 9, 2026 09:58
- Add useApiDiscovery hook for automatic endpoint discovery from metadata
- Add ApiConsolePage component with endpoint tree, search, request/response panels
- Add api-console view to App.tsx routing
- Add API Console entry to sidebar under System section
- Update site-header breadcrumb for api-console view
- Add tests for API discovery logic

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
…aming

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Copilot AI changed the title [WIP] Add global REST API console for automatic discovery and testing feat(studio): Global REST API Console with auto-discovery Mar 9, 2026
@hotlong

hotlong commented Mar 9, 2026

Copy link
Copy Markdown
Collaborator

@copilot 仔细评估是否已经完成了任务中要求的所有开发

Copilot AI and others added 2 commits March 9, 2026 10:18
Replace static query params cheatsheet with interactive form table:
- Add/remove query parameter rows with key/value inputs
- Toggle individual params enabled/disabled (checkbox)
- Quick-add preset buttons for common OData params ($top, $skip, $sort, $select, $count, $filter)
- URL preview shows full path with appended query string
- Replay from history restores query params into form
- Add test for query param URL building logic

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>

Copilot AI commented Mar 9, 2026

Copy link
Copy Markdown
Contributor Author

@copilot 仔细评估是否已经完成了任务中要求的所有开发

经过仔细评估,发现 Query Params 表单化填写 功能缺失(issue 明确要求 "支持 Query Params/Table(OData/数据分页等)表单化填写"),已在 5f198aa 补充完成。

当前所有 Done Criteria 完成状态:

✅ Studio 顶级 API 控制台可自动发现所有 REST API,分组浏览,搜索测试

  • useApiDiscovery hook 从 metadata 自动发现对象和元数据类型
  • 端点按 System / Auth / Metadata / Data:{object} 分组,支持折叠和搜索

✅ 用户无需手写端点,任意 Object 增删自动刷新、端点自动出现

  • 端点从 client.meta.getTypes() + client.meta.getItems() 动态生成
  • Refresh 按钮触发重新发现

✅ 支持请求/响应查看、历史记录、基本参数/Body 表单化填写

  • 响应展示:状态码颜色 + 耗时 + JSON body + 复制
  • 历史记录:50 条,展开查看响应,一键重放
  • Body 编辑器:JSON textarea + bodyTemplate 自动填充
  • Query Params 表单(新增):key/value 行 + checkbox 启用/禁用 + OData 预设按钮 ($top/$skip/$sort/$select/$count/$filter) + URL 预览

✅ 后续任务

  • ROADMAP.md 已更新
  • 5 个新测试覆盖 discovery、分组、query params 构建逻辑

@hotlong
hotlong marked this pull request as ready for review March 9, 2026 11:10
Copilot AI review requested due to automatic review settings March 9, 2026 11:10
@hotlong
hotlong merged commit 562c2f5 into main Mar 9, 2026
5 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a top-level “API Console” view to Studio that auto-discovers REST endpoints from platform metadata and provides a request/response UI for testing them.

Changes:

  • Added ApiConsolePage (endpoint tree + request editor + response viewer + in-memory history/replay).
  • Added useApiDiscovery hook to build endpoint groups from metadata (objects + metadata types) plus some static system/auth endpoints.
  • Wired the new view into Studio navigation (App view routing, sidebar entry, header breadcrumb) and marked the roadmap item complete; added discovery-focused tests.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
apps/studio/src/hooks/use-api-discovery.ts Discovers metadata types/objects and builds grouped endpoint definitions for the API Console
apps/studio/src/components/ApiConsolePage.tsx Renders the global API Console UI and executes requests via fetch
apps/studio/test/api-discovery.test.ts Adds tests for object discovery assumptions, endpoint generation/grouping, and query param URL building
apps/studio/src/App.tsx Adds api-console to the view union and renders ApiConsolePage
apps/studio/src/components/app-sidebar.tsx Adds an “API Console” entry under System and expands view type unions
apps/studio/src/components/site-header.tsx Adds breadcrumb label for the api-console view
ROADMAP.md Marks “Global REST API Console” as completed

Comment on lines +36 to +40
const AUTH_ENDPOINTS: EndpointDef[] = [
{ method: 'POST', path: '/api/auth/sign-in/email', desc: 'Sign in (email)', group: 'Auth', bodyTemplate: { email: 'user@example.com', password: '' } },
{ method: 'POST', path: '/api/auth/sign-up/email', desc: 'Sign up (email)', group: 'Auth', bodyTemplate: { email: '', password: '', name: '' } },
{ method: 'POST', path: '/api/auth/sign-out', desc: 'Sign out', group: 'Auth' },
{ method: 'GET', path: '/api/auth/session', desc: 'Get session', group: 'Auth' },

Copilot AI Mar 9, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auth endpoints here are hardcoded under /api/auth/... and include /session, but the platform AuthPlugin defaults to /api/v1/auth and better-auth’s session endpoint is get-session. As-is, these entries will point to non-existent routes in the default ObjectStack server setup; please align paths with the configured auth basePath (default /api/v1/auth) and the actual better-auth endpoint names.

Copilot uses AI. Check for mistakes.
Comment on lines +70 to +75
// 2. Fetch object names from metadata
let objectNames: string[] = [];
try {
const objectType = metaTypes.includes('objects') ? 'objects' : metaTypes.includes('object') ? 'object' : null;
if (objectType) {
const objectResult = await client.meta.getItems(objectType);

Copilot AI Mar 9, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object discovery currently depends on client.meta.getTypes() succeeding; if it fails (or returns an unexpected shape), metaTypes stays empty and objectType becomes null, so no objects are fetched and no CRUD endpoints are generated. Consider falling back to probing getItems('object')/getItems('objects') directly (or defaulting to 'object') when types discovery is unavailable, so the console still discovers data endpoints in minimal/legacy environments.

Copilot uses AI. Check for mistakes.
Comment on lines +148 to +158
const baseUrl = (client as any)?.baseUrl ?? '';
const fullUrl = `${baseUrl}${effectiveUrl}`;

setLoading(true);
const start = performance.now();

try {
const fetchOptions: RequestInit = {
method: effectiveMethod,
headers: { 'Content-Type': 'application/json' },
};

Copilot AI Mar 9, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sendRequest uses fetch() directly, which bypasses ObjectStackClient’s request wrapper (e.g., tokenAuthorization header) and doesn’t set credentials. This can break the PR’s goal of “inheriting platform authentication” for protected APIs, especially in server mode when baseUrl is absolute. Consider reusing the client’s fetch implementation (or at least forwarding Authorization when configured and setting credentials: 'include' for cookie-based sessions).

Copilot uses AI. Check for mistakes.
Comment on lines +168 to +174
const contentType = res.headers.get('content-type') ?? '';
if (contentType.includes('json')) {
const json = await res.json();
bodyText = JSON.stringify(json, null, 2);
} else {
bodyText = await res.text();
}

Copilot AI Mar 9, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the server responds with Content-Type: application/json but returns a non-JSON body (or an empty body), await res.json() will throw and the catch block reports it as a “Network Error” with status 0, losing the real HTTP status/body. Consider guarding JSON parsing (try JSON parse, fallback to res.text()), so responses are still visible even when the payload is malformed.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Studio 全局 REST API 控制台:自动发现和测试所有 API

3 participants