mirror of https://github.com/vapor/docs.git
Update Japanese translation for basics/content.ja.md
- Add explicit anchors to Japanese headings to match English version
- Fix 15 heading anchors to ensure consistent cross-language navigation
- Japanese headings now have explicit anchors (e.g., ## 概要 {#overview})
- Maintain consistent URL structure between English and Japanese versions
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
7eb0f0620e
commit
916ac09f83
|
|
@ -1,8 +1,8 @@
|
|||
# コンテンツ
|
||||
# コンテンツ {#content}
|
||||
|
||||
Vapor のコンテンツ API を使用すると、Codable な構造体を HTTP メッセージに対して簡単にエンコード・デコードできます。標準では [JSON](https://tools.ietf.org/html/rfc7159) 形式でエンコードされており、[URL-Encoded Form](https://en.wikipedia.org/wiki/Percent-encoding#The_application/x-www-form-urlencoded_type) や [Multipart](https://tools.ietf.org/html/rfc2388) についても即座に使えるサポートがあります。この API はカスタマイズ可能であり、特定の HTTP コンテンツタイプに対するエンコーディングの戦略を追加したり、変更したり、置き換えたりすることができます。
|
||||
|
||||
## 概要
|
||||
## 概要 {#overview}
|
||||
|
||||
Vapor のコンテンツ API の仕組みを理解するためには、HTTP メッセージの基本について知っておく必要があります。以下にリクエストの例を示します。
|
||||
|
||||
|
|
@ -16,7 +16,7 @@ content-length: 18
|
|||
|
||||
このリクエストは、`content-type` ヘッダーを通じて `application/json` メディアタイプでJSON形式のデータが含まれていることを示しています。ヘッダーの後のボディ部分には、約束されたJSONデータが続きます。
|
||||
|
||||
### コンテンツ構造体
|
||||
### コンテンツ構造体 {#content-struct}
|
||||
|
||||
この HTTP メッセージをデコードする最初のステップは、期待される構造にマッチする Codable 型を作成することです。
|
||||
|
||||
|
|
@ -60,7 +60,7 @@ struct Profile: Content {
|
|||
}
|
||||
```
|
||||
|
||||
### サポートされるメディアタイプ
|
||||
### サポートされるメディアタイプ {#supported-media-types}
|
||||
|
||||
以下は、コンテンツ API がデフォルトでサポートしているメディアタイプです。
|
||||
|
||||
|
|
@ -74,11 +74,11 @@ struct Profile: Content {
|
|||
|
||||
すべてのメディアタイプが全ての `Codable` 機能をサポートしているわけではありません。例えば、JSON はトップレベルのフラグメントをサポートしておらず、プレーンテキストはネストされたデータをサポートしていません。
|
||||
|
||||
## クエリ
|
||||
## クエリ {#query}
|
||||
|
||||
Vapor のコンテンツ API は、URL のクエリ文字列にエンコードされたデータの処理に対応しています。
|
||||
|
||||
### デコード
|
||||
### デコード {#decoding}
|
||||
|
||||
URL クエリ文字列をデコードする方法を理解するために、以下の例をご覧ください。
|
||||
|
||||
|
|
@ -122,7 +122,7 @@ GET /hello HTTP/1.1
|
|||
content-length: 0
|
||||
```
|
||||
|
||||
### 単一の値
|
||||
### 単一の値 {#single-value}
|
||||
|
||||
`Content` 構造体へのデコードだけでなく、Vapor はクエリ文字列から単一の値を取得することもサポートしています。これはサブスクリプトを使用して行われます。
|
||||
|
||||
|
|
@ -130,7 +130,7 @@ content-length: 0
|
|||
let name: String? = req.query["name"]
|
||||
```
|
||||
|
||||
## フック
|
||||
## フック {#hooks}
|
||||
|
||||
Vapor は、`Content` タイプに対して `beforeEncode` および `afterDecode` を自動的に呼び出します。デフォルトの実装は何もしませんが、これらのメソッドを使用してカスタムロジックを実行することができます。
|
||||
|
||||
|
|
@ -157,11 +157,11 @@ mutating func beforeEncode() throws {
|
|||
}
|
||||
```
|
||||
|
||||
## デフォルトの上書き
|
||||
## デフォルトの上書き {#override-defaults}
|
||||
|
||||
Vapor の Content API によって使用されるデフォルトのエンコーダーとデコーダーは設定可能です。
|
||||
|
||||
### グローバル
|
||||
### グローバル {#global}
|
||||
|
||||
`ContentConfiguration.global` を使用すると、Vapor がデフォルトで使用するエンコーダーやデコーダーを変更できます。これは、アプリケーション全体でデータの解析やシリアライズ方法を変更するのに便利です。
|
||||
|
||||
|
|
@ -176,7 +176,7 @@ ContentConfiguration.global.use(encoder: encoder, for: .json)
|
|||
|
||||
`ContentConfiguration` の変更は通常、`configure.swift` で行われます。
|
||||
|
||||
### 1回限り
|
||||
### 1回限り {#one-off}
|
||||
|
||||
`req.content.decode` のようなエンコーディングやデコーディングのメソッド呼び出しは、1回限りの使用のためにカスタムコーダーを渡すことをサポートしています。
|
||||
|
||||
|
|
@ -189,11 +189,11 @@ decoder.dateDecodingStrategy = .secondsSince1970
|
|||
let hello = try req.content.decode(Hello.self, using: decoder)
|
||||
```
|
||||
|
||||
## カスタムコーダー
|
||||
## カスタムコーダー {#custom-coders}
|
||||
|
||||
アプリケーションやサードパーティのパッケージは、Vapor がデフォルトでサポートしていないメディアタイプに対応するためにカスタムコーダーを作成することができます。
|
||||
|
||||
### Content
|
||||
### Content {#content}
|
||||
|
||||
Vapor は、HTTP メッセージボディのコンテンツを処理するためのコーダーのために、`ContentDecoder` と `ContentEncoder` の2つのプロトコルを指定しています。
|
||||
|
||||
|
|
@ -211,7 +211,7 @@ public protocol ContentDecoder {
|
|||
|
||||
これらのプロトコルに準拠することで、カスタムコーダーを上記で指定されたように `ContentConfiguration` に登録できます。
|
||||
|
||||
### URL クエリ
|
||||
### URL クエリ {#url-query}
|
||||
|
||||
Vapor は、URL クエリ文字列のコンテンツを処理することができるコーダーのための 2 つのプロトコルを指定しています: `URLQueryDecoder` と `URLQueryEncoder`
|
||||
|
||||
|
|
@ -229,7 +229,7 @@ public protocol URLQueryEncoder {
|
|||
|
||||
これらのプロトコルに準拠することで、`use(urlEncoder:)` および `use(urlDecoder:)` メソッドを使用して、URL クエリ文字列の処理のためにカスタムコーダーを `ContentConfiguration` に登録できます。
|
||||
|
||||
### カスタム `ResponseEncodable`
|
||||
### カスタム `ResponseEncodable` {#custom-responseencodable}
|
||||
|
||||
別のアプローチには、タイプに `ResponseEncodable` を実装するというものがあります。この単純な `HTML` ラッパータイプを考えてみてください。
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue