Skip to content
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
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
589de8c
add ja and translate key feature
ryuckel Jun 2, 2020
2b5be36
translate opinions
ryuckel Jun 2, 2020
e983659
translate by document upgrade
ryuckel Jun 14, 2020
ac92c7e
translate to end
ryuckel Jun 14, 2020
d9f234c
fix text
ryuckel Jun 14, 2020
babbd2f
translate spoiler alert
ryuckel Jun 14, 2020
9e2f971
Merge branch 'master' into feature/add-japanese-translation
ryuckel Jun 14, 2020
d293652
fix translations and typo
ryuckel Jun 25, 2020
7628a0b
Merge branch 'feature/add-japanese-translation' of https://github.com…
ryuckel Jun 25, 2020
75d6ccb
fix translations
ryuckel Jun 25, 2020
2289211
Add Japanese translation for tutorial/index.md
tokusumi Jun 30, 2020
cedd872
Fix tip word
tokusumi Aug 15, 2020
f5154a5
Improve translation
tokusumi Aug 15, 2020
22f8861
add tutorial/response-status-code.md
SwftAlpc Aug 21, 2020
a326b78
Merge branch 'master' into translation/ja-tutorial-response-status-co…
SwftAlpc Aug 23, 2020
de3db05
Merge remote-tracking branch 'upstream/master' into master
SwftAlpc Aug 31, 2020
31a534e
Merge branch 'master' into translation/ja-tutorial-response-status-co…
SwftAlpc Aug 31, 2020
4bef9d4
resolve conflict
SwftAlpc Oct 29, 2020
2ba3b1b
Update docs/ja/docs/tutorial/response-status-code.md
SwftAlpc Oct 29, 2020
d7ecc43
Update docs/ja/docs/tutorial/response-status-code.md
SwftAlpc Oct 29, 2020
559a2e0
Update docs/ja/docs/tutorial/response-status-code.md
SwftAlpc Oct 29, 2020
3da4eab
Update docs/ja/docs/tutorial/response-status-code.md
SwftAlpc Oct 29, 2020
4d7f71c
Update docs/ja/docs/tutorial/response-status-code.md
SwftAlpc Oct 29, 2020
950edb2
Update docs/ja/docs/tutorial/response-status-code.md
SwftAlpc Oct 29, 2020
e93db83
Update docs/ja/docs/tutorial/response-status-code.md
SwftAlpc Oct 29, 2020
fffb6cd
Update docs/ja/docs/tutorial/response-status-code.md
SwftAlpc Oct 29, 2020
c0786d0
Update docs/ja/docs/tutorial/response-status-code.md
SwftAlpc Oct 29, 2020
5bba685
Merge branch 'translation/ja-tutorial-response-status-code-md' of git…
SwftAlpc Oct 29, 2020
2e95898
Update docs/ja/docs/tutorial/response-status-code.md
SwftAlpc Oct 29, 2020
afa65b7
Merge branch 'master' into translation/ja-tutorial-response-status-co…
tiangolo Jun 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
89 changes: 89 additions & 0 deletions docs/ja/docs/tutorial/response-status-code.md
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()`
* など。
Copy link

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".


```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`以上は「情報」のためのものです。。直接使うことはほとんどありません。これらのステータスコードを持つレスポンスはボディを持つことができません。
Copy link

Choose a reason for hiding this comment

The 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!}
```

それらは便利です。それらは同じ番号を保持しており、その方法ではエディタの自動補完を使用してそれらを見つけることができます。
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • It's better to modify "保持しており" to "保持していますが" because "but" is used as a conjunction in the original sentence.
  • In my opinion, It's better to modify the first "それら" to "fastapi.statusの変数" and "その方法" to "`それらの変数を使用する方法" because "それ" or "その" appears three times make the sentence a little difficult to read.


<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}で、ここで宣言しているデフォルトとは異なるステータスコードを返す方法を見ていきます。
1 change: 1 addition & 0 deletions docs/ja/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ nav:
- tutorial/query-params.md
- tutorial/body.md
- tutorial/header-params.md
- tutorial/response-status-code.md
- tutorial/cors.md
- project-generation.md
- alternatives.md
Expand Down