Implementation:Langgenius Dify UseEndpoints
| Knowledge Sources | |
|---|---|
| Domains | Frontend, Plugins, Endpoint Management |
| Last Updated | 2026-02-08 00:00 GMT |
Overview
React Query hooks for full CRUD lifecycle management of plugin endpoints in a Dify workspace, including listing, creating, updating, deleting, enabling, and disabling endpoints.
Description
The UseEndpoints module provides TanStack React Query hooks for managing plugin endpoints within a Dify workspace. Endpoints are externally accessible API interfaces provided by installed plugins. The module includes hooks for listing all endpoints for a given plugin (useEndpointList), invalidating the endpoint list cache (useInvalidateEndpointList), and full mutation hooks for creating (useCreateEndpoint), updating (useUpdateEndpoint), deleting (useDeleteEndpoint), enabling (useEnableEndpoint), and disabling (useDisableEndpoint) endpoints. Each mutation hook accepts optional onSuccess and onError callbacks for custom handling after the operation completes.
Usage
Use these hooks in the Dify plugin management UI to display and manage plugin endpoints. The list hook is used on plugin detail pages, while the mutation hooks power the endpoint configuration forms and toggle controls.
Code Reference
Source Location
- Repository: Langgenius_Dify
- File: web/service/use-endpoints.ts
Signature
export const useEndpointList: (pluginID: string) => UseQueryResult<EndpointsResponse>
export const useInvalidateEndpointList: () => (pluginID: string) => void
export const useCreateEndpoint: (opts: { onSuccess?: () => void, onError?: (error: any) => void }) => UseMutationResult
export const useUpdateEndpoint: (opts: { onSuccess?: () => void, onError?: (error: any) => void }) => UseMutationResult
export const useDeleteEndpoint: (opts: { onSuccess?: () => void, onError?: (error: any) => void }) => UseMutationResult
export const useEnableEndpoint: (opts: { onSuccess?: () => void, onError?: (error: any) => void }) => UseMutationResult
export const useDisableEndpoint: (opts: { onSuccess?: () => void, onError?: (error: any) => void }) => UseMutationResult
Import
import {
useEndpointList,
useInvalidateEndpointList,
useCreateEndpoint,
useUpdateEndpoint,
useDeleteEndpoint,
useEnableEndpoint,
useDisableEndpoint,
} from '@/service/use-endpoints'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| pluginID | string |
Yes (list) | The plugin identifier to list endpoints for |
| pluginUniqueID | string |
Yes (create) | Plugin unique identifier for endpoint creation |
| state | Record<string, any> |
Yes (create/update) | Endpoint settings including name
|
| endpointID | string |
Yes (update/delete/enable/disable) | The endpoint ID to operate on |
| onSuccess | () => void |
No | Callback on successful mutation |
| onError | (error: any) => void |
No | Callback on mutation error |
Outputs
| Name | Type | Description |
|---|---|---|
| EndpointsResponse | EndpointsResponse |
Paginated list of endpoints for the plugin |
| void | void |
Mutation results (create, update, delete, enable, disable) |
Usage Examples
import { useEndpointList, useCreateEndpoint, useEnableEndpoint, useInvalidateEndpointList } from '@/service/use-endpoints'
// List endpoints for a plugin
const { data } = useEndpointList('plugin-abc')
// Create a new endpoint
const invalidate = useInvalidateEndpointList()
const { mutate: create } = useCreateEndpoint({
onSuccess: () => invalidate('plugin-abc'),
})
create({ pluginUniqueID: 'plugin-abc', state: { name: 'My Endpoint', apiKey: 'xxx' } })
// Enable an endpoint
const { mutate: enable } = useEnableEndpoint({
onSuccess: () => invalidate('plugin-abc'),
})
enable('endpoint-123')
Related Pages
- Langgenius_Dify_UseDatasource - Similar hook pattern for data source authentication management
- Langgenius_Dify_Fetch_Layer - Underlying HTTP fetch layer for API requests