DataResource API
업데이트 2026-11-13
DataResource는 앱의 데이터를 저장합니다. Schema는 Data Port를 선언하고, Binding은 Port와 Resource를 연결하며, Grant는 읽기, 쓰기, 연결 권한을 정의합니다. ato.run 인증을 통해 세션을 엽니다.
앱에서 Data Port 사용
호스팅된 앱의 오리진에서 다음 상대 경로를 호출합니다. scope: "user"이면 같은 Instance에서 사용자별 Binding을 사용할 수 있습니다. 공유 Resource에는 별도의 Grant가 필요하며, 이를 취소하면 해당 Grant에 따른 접근이 중단됩니다.
| 메서드와 경로 | 용도 |
|---|---|
GET /__ato/data-ports | Schema, Port 및 현재 Binding을 조회합니다. |
GET /__ato/data-ports/:port/candidates | access에 read 또는 write를 지정해 후보를 조회합니다. |
POST /__ato/data-ports/:port/connect | resource_id, access 및 후보의 access_epoch를 expected_epoch로 전송합니다. |
POST /__ato/data-ports/:port/invoke | operation, arguments, idempotency_key로 Operation을 호출합니다. expected_binding_id로 연결을 고정할 수 있습니다. |
DELETE /__ato/data-ports/:port/connection | 현재 Binding을 해제합니다. |
Operation은 Port에 선언되어 있고 Grant에서 허용해야 합니다. Operation 전용 Grant로 전체 문서를 직접 읽거나 바꾸거나 내보낼 수 없습니다. 동일한 쓰기를 재시도할 때 연결, 입력 및 멱등성 키를 유지합니다. 구현 다이제스트가 다르면 409 protocol_definition_changed가 반환될 수 있습니다.
관리 API
/v1/data-resources에는 ato.run 세션과 신뢰하는 공식 오리진이 필요합니다. 이 경로 아래에서 GET /으로 목록을 보고 POST /으로 Resource를 만듭니다. GET /:resourceId로 문서를 읽고 POST /:resourceId/operations로 교체합니다. 교체 요청에는 operation_id, 최근 조회한 actor_fence와 access, expected_revision, expected_generation, changes: { kind: "replace", value: … }가 필요합니다. 409 data_revision_or_authority_conflict가 발생하면 최신 문서를 읽고 변경을 다시 적용할 수 있는지 확인합니다.
POST /:resourceId/grants로 Grant를 설정하고 DELETE /:resourceId/grants/:grantId로 취소합니다. 설정과 취소 모두 Resource의 현재 access_epoch를 expected_epoch로 보냅니다.