Skip to content

refactor(api): use resource-oriented endpoints in frontend#3181

Open
aofei wants to merge 1 commit into
goplus:devfrom
aofei:REST-api
Open

refactor(api): use resource-oriented endpoints in frontend#3181
aofei wants to merge 1 commit into
goplus:devfrom
aofei:REST-api

Conversation

@aofei
Copy link
Copy Markdown
Member

@aofei aofei commented May 18, 2026

Update frontend API clients and call sites to use the resource-oriented contract from docs/openapi.yaml.

Split collection helpers by ownership scope, rename API modules around current resource names, and pass the /ai-interaction base endpoint to the runtime AI transport.

Fixes #3144

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request performs an extensive refactoring of the API client and endpoint definitions, primarily pluralizing resource paths (e.g., changing /project to /projects) and renaming functions for better clarity. It introduces more specific listing functions for assets, projects, and courses to replace generic ones, and migrates AI description generation to the AIGC module. Additionally, a new put method was added to the base Client class. Feedback was provided to default the payload in the put method to an empty object to ensure consistent Content-Type headers and prevent potential backend parsing errors.

Comment thread spx-gui/src/apis/common/client.ts
@fennoai

This comment was marked as resolved.

Update frontend API clients and call sites to use the resource-oriented
contract from `docs/openapi.yaml`.

Split collection helpers by ownership scope, rename API modules around
current resource names, and pass the `/ai-interaction` base endpoint to
the runtime AI transport.

Fixes goplus#3144

Signed-off-by: Aofei Sheng <aofei@aofeisheng.com>
Comment on lines +55 to +59
return client.get('/course-series', params, { signal }) as Promise<ByPage<CourseSeries>>
}

/** List all course series (owned by all users) by order. 100 items at most. */
export async function listAllCourseSeriesByOrder(signal?: AbortSignal) {
const result = await listCourseSeries(
{ owner: ownerAll, pageIndex: 1, pageSize: 100, orderBy: 'order', sortOrder: 'asc' },
signal
)
return result.data
export function listSignedInUserCourseSeries(params?: ListCourseSeriesParams, signal?: AbortSignal) {
return client.get('/user/course-series', params, { signal }) as Promise<ByPage<CourseSeries>>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

NIP: 去掉 /list 后缀挺好的,但我个人感觉 restful 接口更常见的做法是对同一种资源的 path 用同一个,通过参数来区分 owner / visibility

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

我们这次主要参考的是 GitHub REST API 的风格。比如 GitHub 是用 GET /user/repos 表示当前登录用户的仓库,用 GET /users/{username}/repos 表示某个用户的仓库,用 GET /repositories 表示全局公开仓库列表。

我们这里用 query 参数虽然也可以做,但会让一个 endpoint 承担太多语义,也比较容易重新引入类似 owner=me / owner=* 这种特殊约定,这也是这次想解决的问题之一。

现在这种 /course-series/user/course-series/users/{username}/course-series 的拆法,可以更明确地表达“当前用户的资源”、“某个用户的公开资源”、“全局可见资源”这几种不同上下文。

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

明白,就第一感觉有点别扭,风格统一约定了就行

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.

proposal: make existing product APIs more resource-oriented

2 participants