Skip to content

Conversation

@studioTeaTwo
Copy link
Contributor

#49 です:bow:

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If your company signed a CLA, they designated a Point of Contact who decides which employees are authorized to participate. You may need to contact the Point of Contact for your company and ask to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the project maintainer to go/cla#troubleshoot.
  • In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again.

@studioTeaTwo
Copy link
Contributor Author

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

With `HttpClient`, `@angular/common/http` provides a simplified API for HTTP functionality for use with Angular applications, building on top of the `XMLHttpRequest` interface exposed by browsers.
Additional benefits of `HttpClient` include testability support, strong typing of request and response objects, request and response interceptor support, and better error handling via apis based on Observables.
`HttpClient` は、 `@angular/common/http` の中に含まれていて、Angularアプリケーションで使われるHTTPのためのシンプルなAPIです。ブラウザが公開している `XMLHttpRequest` インターフェースの上にAPIを築きます。
さらに `HttpClient` は、リクエストやレスポンスオブジェクトの強力な型付け、リクエストとレスポンスのインターセプタ、そしてオブザーバブルに基づくAPIを通してエラーハンドリングすることで、テストを簡単にします。
Copy link
Collaborator

Choose a reason for hiding this comment

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

Observableはそのままでよいでしょう

appモジュールに `HttpClientModule` をインポートすると、コンポーネントやサービスに `HttpClient` を注入できるようになります。

## Making a request for JSON data
## JSONデータのリクエストを作る
Copy link
Collaborator

Choose a reason for hiding this comment

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

JSONデータを要求する


You can, however, tell `HttpClient` what type the response will be, which is recommended.
To do so, first you define an interface with the correct shape:
とはいえ、レスポンスがどんな型であるか `HttpClient` に教えることができます。そのために、まず次のように正しい型のインターフェースを定義します。
Copy link
Collaborator

Choose a reason for hiding this comment

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

とはいえ -> しかしながら

// ヘッダーを読める
console.log(resp.headers.get('X-Custom-Header'));
// And access the body directly, which is typed as MyJsonData as requested.
// ボディに直接アクセスするとリクエストしたようにMyJsonData型である。
Copy link
Collaborator

Choose a reason for hiding this comment

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

ボディに直接アクセスすると、要求どおりMyJsonData型である

```

As you can see, the resulting object has a `body` property of the correct type.
ご覧のように、結果として得られるオブジェクトは正しいタイプの `body` プロパティを持っています。
Copy link
Collaborator

Choose a reason for hiding this comment

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

正しい型の

外部依存関係と同様に、HTTPバックエンドは良いテストプラクティスの一環としてモックされる必要があります。 `@angular/common/http` は、このようなっモックを簡単に設定するテストライブラリ `@angular/common/http/testing` を提供します。

### Mocking philosophy
### モックのフィロソフィー
Copy link
Collaborator

Choose a reason for hiding this comment

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

モックの思想

それでおしまいです。これでテストの過程で行われたリクエストは、通常のバックエンドの代わりにテストバックエンドに当たるでしょう。

### Expecting and answering requests
### リクエストのexpectとanswer
Copy link
Collaborator

Choose a reason for hiding this comment

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

リクエストの待ち受けと応答

// this URL, so it will match and return a mock request. The mock request
// can be used to deliver a response or make assertions against the
// request. In this case, the test asserts that the request is a GET.
// そのURLのリクエストがなかった場合、または複数のリクエストが一致した場合、expectOne()はスローする
Copy link
Collaborator

Choose a reason for hiding this comment

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

expectOne()は例外を投げます

```

#### Custom request expectations
#### リクエストのカスタムエクスペクト
Copy link
Collaborator

Choose a reason for hiding this comment

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

独自のリクエスト待ち受け

```

Just as with the `expectOne()` by URL in the test above, if 0 or 2+ requests match this expectation, it will throw.
上記のテストではURLによる `expectOne()` と同様に、0または2以上のリクエストがこの期待値に一致すると、スローされます。
Copy link
Collaborator

Choose a reason for hiding this comment

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

例外を投げます

@lacolaco
Copy link
Collaborator

翻訳ありがとうございます!いくつかの部分で修正をお願いします 🙇

全体を通して、ソースコード中のコメントも「〜です、ます」調に統一していただけますか?

@studioTeaTwo
Copy link
Contributor Author

@lacolaco レビューありがとうございました。修正したので、確認お願いします:bow:

@lacolaco
Copy link
Collaborator

修正ありがとうございました!

@lacolaco lacolaco merged commit 28d1dd4 into angular:master Nov 25, 2017
@studioTeaTwo studioTeaTwo deleted the translation/http branch December 28, 2017 07:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants