-
-
Notifications
You must be signed in to change notification settings - Fork 6.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🌐 Add Japanese translation for docs/ja/docs/tutorial/response-status-code.md
#1942
Merged
alejsdev
merged 30 commits into
tiangolo:master
from
SwftAlpc:translation/ja-tutorial-response-status-code-md
Jan 15, 2024
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
589de8c
add ja and translate key feature
ryuckel 2b5be36
translate opinions
ryuckel e983659
translate by document upgrade
ryuckel ac92c7e
translate to end
ryuckel d9f234c
fix text
ryuckel babbd2f
translate spoiler alert
ryuckel 9e2f971
Merge branch 'master' into feature/add-japanese-translation
ryuckel d293652
fix translations and typo
ryuckel 7628a0b
Merge branch 'feature/add-japanese-translation' of https://github.com…
ryuckel 75d6ccb
fix translations
ryuckel 2289211
Add Japanese translation for tutorial/index.md
tokusumi cedd872
Fix tip word
tokusumi f5154a5
Improve translation
tokusumi 22f8861
add tutorial/response-status-code.md
SwftAlpc a326b78
Merge branch 'master' into translation/ja-tutorial-response-status-co…
SwftAlpc de3db05
Merge remote-tracking branch 'upstream/master' into master
SwftAlpc 31a534e
Merge branch 'master' into translation/ja-tutorial-response-status-co…
SwftAlpc 4bef9d4
resolve conflict
SwftAlpc 2ba3b1b
Update docs/ja/docs/tutorial/response-status-code.md
SwftAlpc d7ecc43
Update docs/ja/docs/tutorial/response-status-code.md
SwftAlpc 559a2e0
Update docs/ja/docs/tutorial/response-status-code.md
SwftAlpc 3da4eab
Update docs/ja/docs/tutorial/response-status-code.md
SwftAlpc 4d7f71c
Update docs/ja/docs/tutorial/response-status-code.md
SwftAlpc 950edb2
Update docs/ja/docs/tutorial/response-status-code.md
SwftAlpc e93db83
Update docs/ja/docs/tutorial/response-status-code.md
SwftAlpc fffb6cd
Update docs/ja/docs/tutorial/response-status-code.md
SwftAlpc c0786d0
Update docs/ja/docs/tutorial/response-status-code.md
SwftAlpc 5bba685
Merge branch 'translation/ja-tutorial-response-status-code-md' of git…
SwftAlpc 2e95898
Update docs/ja/docs/tutorial/response-status-code.md
SwftAlpc afa65b7
Merge branch 'master' into translation/ja-tutorial-response-status-co…
tiangolo File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# レスポンスステータスコード | ||
|
||
レスポンスモデルを指定するのと同じ方法で、レスポンスに使用されるHTTPステータスコードを以下の*path operations*のいずれかの`status_code`パラメータで宣言することもできます。 | ||
|
||
* `@app.get()` | ||
* `@app.post()` | ||
* `@app.put()` | ||
* `@app.delete()` | ||
* など。 | ||
|
||
```Python hl_lines="6" | ||
{!../../../docs_src/response_status_code/tutorial001.py!} | ||
``` | ||
|
||
!!! note "備考" | ||
`status_code`は「デコレータ」メソッド(`get`、`post`など)のパラメータであることに注意してください。すべてのパラメータやボディのように、*path operation関数*のものではありません。 | ||
|
||
`status_code`パラメータはHTTPステータスコードを含む数値を受け取ります。 | ||
|
||
!!! info "情報" | ||
`status_code`は代わりに、Pythonの<a href="https://docs.python.org/3/library/http.html#http.HTTPStatus" class="external-link" target="_blank">`http.HTTPStatus`</a>のように、`IntEnum`を受け取ることもできます。 | ||
|
||
これは: | ||
|
||
* レスポンスでステータスコードを返します。 | ||
* OpenAPIスキーマ(およびユーザーインターフェース)に以下のように文書化します: | ||
|
||
<img src="https://fastapi.tiangolo.com/img/tutorial/response-status-code/image01.png"> | ||
|
||
!!! note "備考" | ||
いくつかのレスポンスコード(次のセクションを参照)は、レスポンスにボディがないことを示しています。 | ||
|
||
FastAPIはこれを知っていて、レスポンスボディがないというOpenAPIドキュメントを生成します。 | ||
|
||
## HTTPステータスコードについて | ||
|
||
!!! note "備考" | ||
すでにHTTPステータスコードが何であるかを知っている場合は、次のセクションにスキップしてください。 | ||
|
||
HTTPでは、レスポンスの一部として3桁の数字のステータスコードを送信します。 | ||
|
||
これらのステータスコードは、それらを認識するために関連付けられた名前を持っていますが、重要な部分は番号です。 | ||
|
||
つまり: | ||
|
||
* `100`以上は「情報」のためのものです。。直接使うことはほとんどありません。これらのステータスコードを持つレスポンスはボディを持つことができません。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a "。" is duplicated. |
||
* **`200`** 以上は「成功」のレスポンスのためのものです。これらは最も利用するであろうものです。 | ||
* `200`はデフォルトのステータスコードで、すべてが「OK」であったことを意味します。 | ||
* 別の例としては、`201`(Created)があります。これはデータベースに新しいレコードを作成した後によく使用されます。 | ||
* 特殊なケースとして、`204`(No Content)があります。このレスポンスはクライアントに返すコンテンツがない場合に使用されます。そしてこのレスポンスはボディを持つことはできません。 | ||
* **`300`** 以上は「リダイレクト」のためのものです。これらのステータスコードを持つレスポンスは`304`(Not Modified)を除き、ボディを持つことも持たないこともできます。 | ||
* **`400`** 以上は「クライアントエラー」のレスポンスのためのものです。これらは、おそらく最も多用するであろう2番目のタイプです。 | ||
* 例えば、`404`は「Not Found」レスポンスです。 | ||
* クライアントからの一般的なエラーについては、`400`を使用することができます。 | ||
* `500`以上はサーバーエラーのためのものです。これらを直接使うことはほとんどありません。アプリケーションコードやサーバーのどこかで何か問題が発生した場合、これらのステータスコードのいずれかが自動的に返されます。 | ||
|
||
!!! tip "豆知識" | ||
それぞれのステータスコードとどのコードが何のためのコードなのかについて詳細は<a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Status" class="external-link" target="_blank"><abbr title="Mozilla Developer Network">MDN</abbr> HTTP レスポンスステータスコードについてのドキュメント</a>を参照してください。 | ||
|
||
## 名前を覚えるための近道 | ||
|
||
先ほどの例をもう一度見てみましょう: | ||
|
||
```Python hl_lines="6" | ||
{!../../../docs_src/response_status_code/tutorial001.py!} | ||
``` | ||
|
||
`201`は「作成完了」のためのステータスコードです。 | ||
|
||
しかし、それぞれのコードの意味を暗記する必要はありません。 | ||
|
||
`fastapi.status`の便利な変数を利用することができます。 | ||
|
||
```Python hl_lines="1 6" | ||
{!../../../docs_src/response_status_code/tutorial002.py!} | ||
``` | ||
|
||
それらは便利です。それらは同じ番号を保持しており、その方法ではエディタの自動補完を使用してそれらを見つけることができます。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
<img src="https://fastapi.tiangolo.com/img/tutorial/response-status-code/image02.png"> | ||
|
||
!!! note "技術詳細" | ||
また、`from starlette import status`を使うこともできます。 | ||
|
||
**FastAPI** は、`開発者の利便性を考慮して、fastapi.status`と同じ`starlette.status`を提供しています。しかし、これはStarletteから直接提供されています。 | ||
|
||
## デフォルトの変更 | ||
|
||
後に、[高度なユーザーガイド](../advanced/response-change-status-code.md){.internal-link target=_blank}で、ここで宣言しているデフォルトとは異なるステータスコードを返す方法を見ていきます。 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel it's a little unnatural for translating "etc" to "など" and I think it may be kept an English word "etc".