---
url: /reference/interface/bridge/remote.md
---

# remote

`remote` 使你的应用能够调用 PingCode 外部平台上的远程后端服务。

导入：

```typescript
import { remote } from '@pc-nexus/bridge';
```

内置方法：

## **invoke**

允许应用能够与托管在外部的远程服务进行集成。在请求被转发到远程服务之前，会先进行验证，并添加必要的认证信息，如果配置了 OAuth 令牌，则会使用 OAuth 令牌。

### **函数签名**

```typescript
function invoke(options: RemoteInvokeOptions): Promise<Response>;

type RemoteInvokeOptions = { path: string; } & Pick<RequestInit, "headers" | "body" | "method">;
```

### **参数**

`RemoteInvokeOptions` 类型定义如下：

### **返回值**

参见 WHATWG [响应对象](https://fetch.spec.whatwg.org/#response-class) ，通过  `Promise` 返回。

### **示例**

```typescript
import { remote } from '@pc-nexus/bridge';

const response = await remote.invoke({
  path: '/my-api',
  method: 'POST',
  headers: {
    'content-type': 'application/json',
  },
  body: JSON.stringify({
    message: 'hello',
  }),
});

console.log(response.status);

const data = await response.json();
console.log(data);
```

## **request**

允许应用在前端代码中直接向远程服务发送请求，与 `invoke` 方法不同，即使为远程配置了 OAuth 令牌， `request` 方法也不会包含这些令牌。

### **函数签名**

```typescript
function request(remoteKey: string, options?: RemoteRequestOptions): Promise<Response>;

type RemoteRequestOptions = { path: string; } & Omit<RequestInit, "signal">;
```

### **参数**

`RemoteRequestOptions` 类型定义如下：

### **返回值**

参见 WHATWG [响应对象](https://fetch.spec.whatwg.org/#response-class) ，通过  `Promise` 返回。

### **示例**

```typescript
import { remote } from '@pc-nexus/bridge';

const response = await remote.request('my-remote', {
  path: '/my-api',
  method: 'POST',
  headers: {
    'content-type': 'application/json',
  },
  body: JSON.stringify({
    message: 'hello',
  }),
});

console.log(response.status);

const data = await response.json();
console.log(data);
```
