FNetwork
Make HTTP requests through univerAPI.getNetwork(). Register the Network plugin and import its Facade entry before using these methods. The response wraps the body, status, and headers; getSSE returns an observable stream1.
The following example assumes your application serves a JSON list at /api/items:
const network = univerAPI.getNetwork()const response = await network.get<{ id: string }[]>('/api/items')console.log(response.status, response.body)Access
Access through:
Setup
Register @univerjs/network or a preset that includes it. In plugin mode, import @univerjs/network/facade. Additional methods below require their listed plugin packages. See Facade setup.
@univerjs/network
FNetwork.delete
Send DELETE request to the server.
delete<T>(url: string, params?: IRequestParams): Promise<HTTPResponse<T>>Parameters
url— Required. The requested URLparams— Optional. Request options, including query parameters, headers, and response type
Returns
A promise resolving to the HTTP response with a body of type T.
Types: HTTPResponse · Promise · IRequestParams
Package: @univerjs/network · Type definitions
FNetwork.get
Send a GET request to the server.
get<T>(url: string, params?: IRequestParams): Promise<HTTPResponse<T>>Parameters
url— Required. The requested URL.params— Optional. Request options, including query parameters, headers, and response type.
Returns
A promise resolving to the HTTP response with a body of type T.
Types: HTTPResponse · Promise · IRequestParams
Package: @univerjs/network · Type definitions
FNetwork.getSSE
Request for a stream of server-sent events. Instead of a single response, the server sends a stream of responses,
Univer wraps the stream in an Observable which you can call subscribe on.
getSSE<T>(method: HTTPRequestMethod, url: string, params?: IPostRequestParams): Observable<HTTPEvent<T>>Parameters
method— Required. HTTP request methodurl— Required. The requested URLparams— Optional. params Request options, including body, query parameters, headers, and response type
Returns
An observable of HTTP events with response data of type T.
Types: HTTPEvent · Observable · HTTPRequestMethod · IPostRequestParams
Package: @univerjs/network · Type definitions
FNetwork.patch
Send PATCH request to the server.
patch<T>(url: string, params?: IPostRequestParams): Promise<HTTPResponse<T>>Parameters
url— Required. The requested URLparams— Optional. Request options, including body, query parameters, headers, and response type
Returns
A promise resolving to the HTTP response with a body of type T.
Types: HTTPResponse · Promise · IPostRequestParams
Package: @univerjs/network · Type definitions
FNetwork.post
Send a POST request to the server.
post<T>(url: string, params?: IPostRequestParams): Promise<HTTPResponse<T>>Parameters
url— Required. The requested URL.params— Optional. Request options, including body, query parameters, headers, and response type.
Returns
A promise resolving to the HTTP response with a body of type T.
Types: HTTPResponse · Promise · IPostRequestParams
Package: @univerjs/network · Type definitions
FNetwork.put
Send a PUT request to the server.
put<T>(url: string, params?: IPostRequestParams): Promise<HTTPResponse<T>>Parameters
url— Required. The requested URLparams— Optional. Request options, including body, query parameters, headers, and response type
Returns
A promise resolving to the HTTP response with a body of type T.
Types: HTTPResponse · Promise · IPostRequestParams
Package: @univerjs/network · Type definitions
Footnotes
-
An RxJS Observable can emit multiple values over time, whereas a Promise resolves once. Subscribe to consume the stream and unsubscribe when it is no longer needed; SSE carries server-to-client events over HTTP. ↩
How is this guide?