API Gateway では、サービスの実装を問わず、すべてのサービスで一貫して明確に定義された REST API を使用して、サービスに安全にアクセスできます。一貫性のある API とは、次のような API のことです。
アプリ デベロッパーがサービスをより簡単に使用できる
パブリック API に影響を与えることなく、バックエンド サービスの実装を変更できる
Google Cloud Platform(GCP)に組み込まれているスケーリング、モニタリング、セキュリティ機能を活用できる
次の図は、アプリ デベロッパーが API Gateway を介してバックエンド サービスにリクエストを送信する方法を示しています。
API Gateway を使用すると、アプリ デベロッパーは REST API を使用してアプリを実装します。すべての API が API Gateway でホストされるため、アプリ デベロッパーはすべてのバックエンド サービスで一貫したインターフェースを使用できます。
API Gateway に API をデプロイすることで、バックエンド サービスを更新できます。また、API を変更することを必要とせずに、あるアーキテクチャから別のアーキテクチャにサービスを移動することもできます。サービスの API の一貫性が維持されている限り、バックエンドの根本的な変更を理由に、アプリ デベロッパーはデプロイ済みのアプリを変更する必要はありません。
API Gateway は、API を作成、共有、維持、保護するためのホスティング、ロギング、モニタリングなどの機能を提供する分散 API 管理システムです。 API Gateway は Google Cloud とネイティブに統合されており、トラフィック管理、認可、モニタリングなど、同時実行 API 呼び出しの処理に関連するすべてのタスクを処理します。
API とは
API とは、あるアプリケーションが別のアプリケーションの機能やデータを利用できるようにするインターフェースです。安定した明確なエントリ ポイントを定義することで、他のデベロッパーによって構築されたアプリケーション ロジックへのアクセスや再利用を行うことができます。
この情報を使用して、この API に対して次の cURL リクエストを行い、書籍に関する情報を取得できます。
curl -X GET https://www.mybooksapi.com/books/info?isbn=0385504217
このサービスには、データ形式や HTTP レスポンス コードの説明など、明確に定義された API があるため、アプリ デベロッパーはバックエンド サービスの基盤となる実装について何も知らなくても問題ありません。
API を使用するアプリケーションには変更が多発するため、API には API プロバイダと API コンシューマとの契約も含まれています。この契約により、時間の経過とともに API が予測可能な方法で変更されることが保証されます。たとえば、book API を更新して title や author などのクエリ パラメータを追加するか、レスポンスの JSON を変更して書籍に関する情報を追加します。
API の定義
API Gateway にデプロイされた API を OpenAPI 2.0 仕様として定義します。API 定義の主なコンポーネントは次のとおりです。
バックエンド サービスの URL またはエントリ ポイント
API へのリクエストで渡されるデータのデータ形式
API からのレスポンスでサービスから返されるデータのデータ形式
サービスへのアクセス制御に使用される認証メカニズム
API を定義したら、gcloud コマンドライン インターフェースを使用して、GCP の API 構成にアップロードします。
API Gateway への API 構成のデプロイ
API を作成するには、API Gateway に API 構成をデプロイします。gcloud コマンドを使用して API 構成をデプロイします。
API 構成がデプロイされると、クライアントは API に対して REST 呼び出しを行うことができます。
API の管理
デプロイして実行すると、使用状況の指標やログなどの API アクティビティをモニタリングできます。クライアントが API にリクエストを送信すると、API Gateway はリクエストとレスポンスに関する情報をログに記録します。API Gateway は、レイテンシ、トラフィック、エラーも追跡します。
時間の経過とともに、新しい機能を追加したり、パフォーマンスを改善したり、API の問題を修正したりするために、デプロイされた API を更新することがあります。デプロイされた API を更新するには、API 定義の OpenAPI 仕様を更新してから、API をアップロードして再デプロイします。
API アクセスの制御
API Gateway を使用すると、クライアントが API にアクセスする前に認証を要求するように API を構成できます。API Gateway では、以下を含め Cloud Endpoints で使用されているものと同じ認証メカニズムと構文がサポートされています。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-04-22 UTC。"],[[["\u003cp\u003eAPI Gateway provides secure access to services through a consistent REST API, simplifying consumption for app developers regardless of the underlying service implementation.\u003c/p\u003e\n"],["\u003cp\u003eIt allows for changes in backend service architecture without requiring modifications to the public API or app developers' deployed applications.\u003c/p\u003e\n"],["\u003cp\u003eAPI Gateway is a distributed API management system offering hosting, logging, monitoring, and security features, natively integrated with Google Cloud, to help create, share, maintain, and secure APIs.\u003c/p\u003e\n"],["\u003cp\u003eAn API defines a contract between providers and consumers, specifying entry points, data formats, and authentication, ensuring predictable changes over time and providing an interface for applications to consume data or functionalities from another application.\u003c/p\u003e\n"],["\u003cp\u003eAPI Gateway supports authentication methods like API keys and Google ID tokens, allowing you to control access to your API and manage what authenticated users can do.\u003c/p\u003e\n"]]],[],null,["# About API Gateway\n=================\n\nWeb-based services today provide a huge variety of functionality, meaning everything from map, weather, and image services, to games, auctions, and many other service types. Service providers have many options for how to implement, deploy, and manage their services. For example, one service might be developed in Java or .NET, while another uses Node.js.\n\nBackend implementations can also vary for a single service provider. A service provider might have legacy services implemented using one architecture, and new services implemented using a completely different architecture.\n\nRegardless of implementation, web-based services all require a way to make the services available to app developers. Often these services are exposed as a set of HTTP endpoints. Depending on the service, the endpoint might also return data, formatted as XML or JSON, to the client app.\n\nAbout Google Cloud services\n---------------------------\n\nWhen developing your services on the Google Cloud, you have many options for how you implement the services, such as [Cloud Run functions](/functions/docs), [Cloud Run](/run/docs), and [App Engine standard environment](/appengine/docs). The flexibility of Google Cloud means you choose the correct backend architecture for your service requirements.\n\nApp developers are the customers of backend services. App developers consume your services to implement apps for mobile devices or tablets, through apps running in a browser, or through any other type of app that can make a service request.\n\nExposing services publicly over the web can be challenging. To be successful, a service provider must:\n\n- Authenticate access to the service\n- Secure data transport between clients and the service\n- Protect the service from malicious attacks\n- Scale the service as usage increases or decreases\n- Provide the backend operations team with a way to monitor and track service usage\n- Track usage to provide accurate billing information\n\nAlso, if your services use different interfaces and protocols, then accessing these services can be a challenge to app developers. Developers must not only learn and understand each service interface, but they must also monitor the different services for changes, and then update and redeploy apps as necessary.\n\nAPI Gateway\n-----------\n\nAPI Gateway enables you to provide secure access to your services through a well-defined REST API that is consistent across all of your services, regardless of service implementation. A consistent API:\n\n- Makes it easy for app developers to consume your services\n- Enables you to change the backend service implementation without affecting the public API\n- Enables you to take advantage of the scaling, monitoring, and security features built into the Google Cloud Platform (GCP)\n\nThe following image shows app developers making requests to your backend services through API Gateway:\n\nUsing API Gateway, app developers consume your REST APIs to implement apps. Because all APIs are hosted on API Gateway, app developers see a consistent interface across all backend services.\n\nBy deploying your APIs on API Gateway, you can update the backend service, or even move the service from one architecture to another, without having to change the API. As long as the API to your service stays consistent, app developers won't have to modify deployed apps because of underlying changes on your backend.\n\nAPI Gateway is a distributed API management system that also provides hosting, logging, monitoring, and other features to help you create, share, maintain, and secure your APIs. API Gateway is natively integrated with Google Cloud and handles all the tasks involved in processing concurrent API calls, including traffic management, authorization, and monitoring.\n\nWhat is an API?\n---------------\n\nAn API is an interface that makes it possible for one application to consume capabilities or data from another application. By defining stable and well-documented entry points, APIs enable developers to access and reuse application logic built by other developers.\n\nFor example, the following table describes an example of a REST API that could return information about a book:\n\nUsing this information, you could make the following cURL request to this API to get information about a book: \n\n curl -X GET https://www.mybooksapi.com/books/info?isbn=0385504217\n\nBecause this service has a well-defined API, including a description of data formats and HTTP response codes, the app developer does not need to know anything about the underlying implementation of the backend service.\n\nSince applications that consume APIs are sensitive to changes, APIs also imply a contract between API providers and API consumers. The contract assures that over time the API will change in a predictable manner. For example, the book API might be updated to add additional query parameters, such as `title` or `author`, or change the response JSON to add additional information about the book.\n\n### Defining an API\n\nYou define an API deployed on API Gateway as an OpenAPI 2.0 spec.\nThe key components of an API definition include:\n\n- The URL, or entry point, of the backend service\n- The data format of any data passed on a request to the API\n- The data format of any data returned by the service in the response from the API\n- The authentication mechanism used to control access to the service\n\nAfter you define your API, use the [gcloud](/sdk/gcloud/reference) command line interface to upload it to an API config on GCP:\n\n### Deploying an API config on API Gateway\n\nTo create your API, you deploy the API config on API Gateway.\nUse the `gcloud` command to deploy the API config:\n\nAfter the API config is deployed, your clients can make REST calls to the API.\n\n### Managing an API\n\nOnce deployed and running, you can monitor API activity, such as usage metrics and logs. When a client makes a request to your API, API Gateway logs information about the request and response. API Gateway also tracks latency, traffic, and errors.\n\nOver time, you might want to update a deployed API to add new capabilities, improve performance, or to fix issues with the API. To update a deployed API, you update the OpenAPI spec for the API definition, then upload and redeploy the API.\n\n### Controlling API access\n\nAPI Gateway lets you configure your API to require authentication before the client can access the API. API Gateway supports the same authentication mechanism and syntax as used by [Cloud Endpoints](/endpoints/docs), including using:\n\n- [API keys](/endpoints/docs/openapi/restricting-api-access-with-api-keys)\n- [Authentication methods at Google](https://cloud.google.com/docs/authentication/#service_accounts)\n- [Google ID tokens](/endpoints/docs/openapi/glossary#google_id_token)\n\nYou can also use the Google Cloud console to share your API with other developers so they can enable your API and generate API keys to call it.\n\nAlong with defining an authentication mechanism to verify a user's identity, your API also needs to decide what the authenticated user can do with your API. For more information, see [Authentication methods at Google](https://cloud.google.com/docs/authentication).\n\nWhat's next\n-----------\n\n- [API Gateway Architecture](/api-gateway/docs/architecture-overview)"]]