Skip to content

Commit 437ca44

Browse files
author
Luke Sneeringer
committed
feat: AIP-156 – Singleton resources
1 parent fd72558 commit 437ca44

3 files changed

Lines changed: 122 additions & 0 deletions

File tree

aip/general/0156/aip.md.j2

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Singleton resources
2+
3+
APIs sometimes need to represent a resource where exactly one instance of the
4+
resource always exists within any given parent. A common use case for this is
5+
for a configuration object, with distinct permissions from the parent resource.
6+
7+
## Guidance
8+
9+
An API **may** define _singleton resources_. A singleton resource **must**
10+
always exist by virtue of the existence of its parent, with one and exactly one
11+
per parent.
12+
13+
```http
14+
GET /v1/publishers/{publisher}/config HTTP/2
15+
Host: library.googleapis.com
16+
Accept: application/json
17+
```
18+
19+
- Singleton resources **must not** have a user-provided or system-generated ID;
20+
their canonical URI includes the name of their parent followed by one
21+
static-segment.
22+
- Example: `publishers/lacroix/config`
23+
- Singleton resources **should** define a `GET` operation, which **must**
24+
correspond to `GET` for individual resources (AIP-131), and **not** `GET` for
25+
collections (AIP-132).
26+
- Singleton resources **should** define a `PATCH` operation, which **must**
27+
correspond to a standard update (AIP-134).
28+
- Singleton resources **must not** define operations to create (AIP-133) or
29+
delete (AIP-135) the resource.
30+
- The service **should** reply with an HTTP 405 (Method Not Allowed) error if
31+
the user sends a `POST` or `DELETE` request.
32+
- Singleton resources **may** define custom methods as appropriate.
33+
34+
## Interface Definitions
35+
36+
{% tab proto %}
37+
38+
{% sample 'singleton.proto', 'rpc GetConfig', 'rpc UpdateConfig' %}
39+
40+
{% endtabs %}

aip/general/0156/aip.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
id: 156
3+
state: approved
4+
created: 2019-05-12
5+
placement:
6+
category: resource-design
7+
order: 70

aip/general/0156/singleton.proto

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
syntax = "proto3";
16+
17+
import "google/api/annotations.proto";
18+
import "google/api/client.proto";
19+
import "google/api/resource.proto";
20+
import "google/protobuf/field_mask.proto";
21+
22+
service Library {
23+
// Get the configuration for a author.
24+
rpc GetConfig(GetConfigRequest) returns (Config) {
25+
option (google.api.http) = {
26+
get: "/v1/{name=authors/*/config}"
27+
};
28+
option (google.api.method_signature) = "name";
29+
}
30+
31+
// Update the configuration for a author.
32+
rpc UpdateConfig(UpdateConfigRequest) returns (Config) {
33+
option (google.api.http) = {
34+
patch: "/v1/{config.name=authors/*/config}"
35+
body: "config"
36+
};
37+
option (google.api.method_signature) = "config,update_mask";
38+
}
39+
}
40+
41+
// Request message to get a author's config.
42+
message GetConfigRequest {
43+
// The name of the config.
44+
// Format: authors/{author}/config
45+
string name = 1 [(google.api.resource_reference) = {
46+
type: "library.googleapis.com/Config"
47+
}];
48+
}
49+
50+
// Request message to update a author's config.
51+
message UpdateConfigRequest {
52+
// The new config object.
53+
Config config = 1;
54+
55+
// The list of fields to be updated.
56+
google.protobuf.FieldMask update_mask = 2;
57+
}
58+
59+
// The configuration options for a author.
60+
message Config {
61+
option (google.api.resource) = {
62+
type: "library.googleapis.com/Config"
63+
pattern: "authors/{author}/config"
64+
};
65+
66+
// The name of the config.
67+
// Format: authors/{author}/config
68+
string name = 1;
69+
70+
// The author's preferred language.
71+
string language_code = 2;
72+
73+
// The time zone where the author resides.
74+
string time_zone = 3;
75+
}

0 commit comments

Comments
 (0)