Skip to content

Commit 44c8ed2

Browse files
Add application/yaml section in api-concepts (#48417)
* fix: add application/yaml section in api-concepts * nit fix: breaking the request and response into distinct code blocks * fix: split the request and response into separate code blocks
1 parent 05afa58 commit 44c8ed2

File tree

1 file changed

+51
-15
lines changed

1 file changed

+51
-15
lines changed

content/en/docs/reference/using-api/api-concepts.md

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -126,18 +126,9 @@ virtual resource type would be used if that becomes necessary.
126126

127127
Over HTTP, Kubernetes supports JSON and Protobuf wire encodings.
128128

129-
{{% note %}}
130-
Although YAML is widely used to define Kubernetes manifests locally, Kubernetes does not
131-
support the [`application/yaml`](https://www.rfc-editor.org/rfc/rfc9512.html) media type
132-
for API operations.
133-
134-
All JSON documents are valid YAML, so you can also use a JSON API response anywhere that is
135-
expecting a YAML input.
136-
{{% /note %}}
137-
138129
By default, Kubernetes returns objects in [JSON serialization](#json-encoding), using the
139-
`application/json` media type. Although JSON is the default, clients may request the more
140-
efficient binary [Protobuf representation](#protobuf-encoding) for better performance at scale.
130+
`application/json` media type. Although JSON is the default, clients may request a response in
131+
YAML, or use the more efficient binary [Protobuf representation](#protobuf-encoding) for better performance at scale.
141132

142133
The Kubernetes API implements standard HTTP content type negotiation: passing an
143134
`Accept` header with a `GET` call will request that the server tries to return
@@ -161,7 +152,9 @@ For example:
161152

162153
```
163154
GET /api/v1/pods
164-
---
155+
```
156+
157+
```
165158
200 OK
166159
Content-Type: application/json
167160
@@ -175,7 +168,9 @@ For example:
175168
Content-Type: application/json
176169
Accept: application/json
177170
… JSON encoded Pod object
178-
---
171+
```
172+
173+
```
179174
200 OK
180175
Content-Type: application/json
181176
@@ -186,6 +181,43 @@ For example:
186181
}
187182
```
188183

184+
### YAML resource encoding {#yaml-encoding}
185+
Kubernetes also supports the [`application/yaml`](https://www.rfc-editor.org/rfc/rfc9512.html) media type for both requests and responses. [`YAML`](https://yaml.org/) can be used for defining Kubernetes manifests and API interactions.
186+
187+
For example:
188+
189+
1. List all of the pods on a cluster in YAML format
190+
```
191+
GET /api/v1/pods
192+
Accept: application/yaml
193+
```
194+
195+
```
196+
200 OK
197+
Content-Type: application/yaml
198+
199+
… YAML encoded collection of Pods (PodList object)
200+
```
201+
202+
1. Create a pod by sending YAML-encoded data to the server, requesting a YAML response:
203+
```
204+
POST /api/v1/namespaces/test/pods
205+
Content-Type: application/yaml
206+
Accept: application/yaml
207+
… YAML encoded Pod object
208+
```
209+
210+
```
211+
200 OK
212+
Content-Type: application/yaml
213+
214+
apiVersion: v1
215+
kind: Pod
216+
metadata:
217+
name: my-pod
218+
219+
```
220+
189221
### Kubernetes Protobuf encoding {#protobuf-encoding}
190222

191223
Kubernetes uses an envelope wrapper to encode [Protobuf](https://protobuf.dev/) responses.
@@ -202,7 +234,9 @@ For example:
202234
```
203235
GET /api/v1/pods
204236
Accept: application/vnd.kubernetes.protobuf
205-
---
237+
```
238+
239+
```
206240
200 OK
207241
Content-Type: application/vnd.kubernetes.protobuf
208242
@@ -217,7 +251,9 @@ For example:
217251
Content-Type: application/vnd.kubernetes.protobuf
218252
Accept: application/json
219253
… binary encoded Pod object
220-
---
254+
```
255+
256+
```
221257
200 OK
222258
Content-Type: application/json
223259

0 commit comments

Comments
 (0)